Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6856823

Rhino RegExp parser bugs(javax.script)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 6
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      the bug in Rhino. it can not pass when the unescaped word in "[]"group.
      such as a base64 filter: /[a-zA-Z+/=]/; it is valid in ECMAScript,but faild in jdk6.

      sun.org.mozilla.javascript.internal/TokenStream.java

      line:854

      fix to:
          void readRegExp(int startToken)
              throws IOException
          {
              stringBufferTop = 0;
              if (startToken == Token.ASSIGN_DIV) {
                  // Miss-scanned /=
                  addToString('=');
              } else {
                  if (startToken != Token.DIV) Kit.codeBug();
              }
              
              
              int depth = 0;//ADD BY JINDW
              int c;
              while ((c = getChar()) != '/' || depth !=0) {
                  if (c == '\n' || c == EOF_CHAR) {
                      ungetChar(c);
                      throw parser.reportError("msg.unterminated.re.lit");
                  }
                  /** comment by jindw
                  if (c == '\\') {
                      addToString(c);
                      c = getChar();
                  }
                  **/
                  //ADD BY JINDW BEGIN{
                  if(c=='['){
                   depth = 1;
                  }else if(c==']'){
                   depth = 0;
                  }else if (c == '\\') {
                      addToString(c);
                      c = getChar();
                  }
      // if (c == '\\') {
      // addToString(c);
      // c = getChar();
      // }
                  //ADD BY JINDW END}

                  addToString(c);
              }
              int reEnd = stringBufferTop;

              while (true) {
                  if (matchChar('g'))
                      addToString('g');
                  else if (matchChar('i'))
                      addToString('i');
                  else if (matchChar('m'))
                      addToString('m');
                  else
                      break;
              }

              if (isAlpha(peekChar())) {
                  throw parser.reportError("msg.invalid.re.flag");
              }

              this.string = new String(stringBuffer, 0, reEnd);
              this.regExpFlags = new String(stringBuffer, reEnd,
                                            stringBufferTop - reEnd);
          }



      REPRODUCIBILITY :
      This bug can be reproduced always.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sundar Sundararajan Athijegannathan
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: