Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: [Mondrian] Bug in Util.singleQuoteString: backslashes not beingproperly escaped

  1. #1
    Jason Schlesinger Guest

    Default [Mondrian] Bug in Util.singleQuoteString: backslashes not beingproperly escaped

    In Mondrian.olap.Util.singleQuoteString:

    The line:
    String s0 = replace(val, "'", "''");

    Should be replaced with:
    String s0 = replace(replace(val, "'", "''"), "\\", "\\\\");
    or similar in order to escape backslashes. Currently backslashes in strings escape the next character in the string, or in the case the backslash is the last character in the string, it escapes the encapsulating quote.

    thanks,
    Jason

    _______________________________________________
    Mondrian mailing list
    Mondrian (AT) pentaho (DOT) org
    http://lists.pentaho.org/mailman/listinfo/mondrian

  2. #2
    Julian Hyde Guest

    Default RE: [Mondrian] Bug in Util.singleQuoteString: backslashes not beingproperly escaped

    > Jason Schlesinger wrote:
    >
    > In Mondrian.olap.Util.singleQuoteString:
    >
    > The line:
    > String s0 = replace(val, "'", "''");
    >
    > Should be replaced with:
    > String s0 = replace(replace(val, "'", "''"), "\\", "\\\\");
    > or similar in order to escape backslashes. Currently
    > backslashes in strings escape the next character in the
    > string, or in the case the backslash is the last character in
    > the string, it escapes the encapsulating quote.


    That function is intended to create SQL or MDX strings. Those languages
    don't escape backslashes. (Unless you count some of MySQL's brain-dead
    dialects, which I don't.)

    I'm guessing you may be trying to embed an MDX string literal in Java. E.g.

    String mdx =
    "with member [Measures].[Constant string] as 'my string' "
    + "select [Measures].[Constant string] on 0 "
    + "from [Sales]";

    If so, first use singleQuoteString to deal with any single-quotes in the MDX
    string. Then quote the string for Java -- that will deal with any embedded
    backslashes, double quotes, and control characters.

    Julian

    _______________________________________________
    Mondrian mailing list
    Mondrian (AT) pentaho (DOT) org
    http://lists.pentaho.org/mailman/listinfo/mondrian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.