Bug 1297 - RSL code doesn't handle quoted strings properly
: RSL code doesn't handle quoted strings properly
: CoG jglobus
: 1.1
: All All
: P2 normal
: ---
Assigned To:
  Show dependency treegraph
Reported: 2003-10-15 20:04 by
Modified: 2005-12-05 18:11 (History)



You need to log in before you can comment on or make changes to this bug.

Description From 2003-10-15 20:04:36
The RSLParser class doesn't handle certain quoted strings properly, most
noticably the empty string. For example, the following RSL:


when parsed and then unparsed by RSLParser, produces:

  &( scratchdir = "'" )

Worse yet, if you use double-quotes instead:


you get the following unparsed RSL, which isn't even legal:

  &( scratchdir = """ )

A similar problem happens for RSLs like the following:


All of these examples were unparsed with explicit quoting enabled.
The problem seems to be in the unQuotify() function in RSLParser.jj. When
searching for escaped quotes in a quote literal (cases where the quoting
character occurs twice consecutively in the string, signalling the quoting
character should appear once in the string), it's not handling the corner cases
very well (when escaped quoting characters are all that appear in the string or
an empty string is quoted).

Another problem occurs when unparsing strings literals. If the string literal
contains a double-quote, it's not escaped properly when toRSL() is called with
explicit quoting. For example, this RSL:


when parsed and then unparsed with explicit quoting, comes out as follows:

  &( scratchdir = "123"456" )

which is not a legal representation. The problem here seems to be in the toRSL()
function of the Value class. It's not escaping any double-quotes in the string
when explicit quoting is specified.
------- Comment #1 From 2003-10-15 20:34:58 -------
Here's a new version of RSLParser.unQuotify() that fixes the quoting problem.
simply have the code in the for-loop ignore the surrounding quote characters.

  private String unQuotify(String str, char quoteChar) {

      char curChar;

      char nextChar;

      int size = str.length();

      StringBuffer buf = new StringBuffer(size-2);

      for (int i=1;i<size-1;i++) {

        curChar = str.charAt(i);

        if (curChar == quoteChar) {

          if (i+1 < size-1) {


            nextChar = str.charAt(i);

            if (nextChar == quoteChar) {


            } else {




        } else {




      return buf.toString();

------- Comment #2 From 2003-10-15 20:39:41 -------
I just found another quoting problem. RSLParser doesn't handle the carat-based
quoting described in the RSL spec: http://www-fp.globus.org/gram/rsl_spec1.html
------- Comment #3 From 2003-10-15 20:51:51 -------
Here's a fix for the quoting problem in the Value class. I added a function for
quoting the string literal and use it in toRSL():

    private String quotify(String str) {
        char curChar;
        char quoteChar = '"';
        int size = str.length();
        StringBuffer buf = new StringBuffer(size+2);


        for (int i=0;i<size;i++) {
            curChar = str.charAt(i);
            if (curChar == quoteChar) {
        return buf.toString();

    public void toRSL(StringBuffer buf, boolean explicitConcat) {

        if ( explicitConcat ) {
            buf.append( quotify( value ) );
        } else {
            buf.append( value );
        if (concatValue == null) return;

        if (explicitConcat) buf.append(" # ");
        concatValue.toRSL(buf, explicitConcat);
------- Comment #4 From 2003-10-21 17:10:27 -------
The fixes were committed to the cvs. Thanks! 
The carat-based quoting is not supported in the RSLParser (this is/was 
mentioned in the javadocs)