You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2001/06/19 01:18:58 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/utils/regex ParserForXMLSchema.java RegexParser.java

elena       01/06/18 16:18:57

  Modified:    java/src/org/apache/xerces/utils/regex
                        ParserForXMLSchema.java RegexParser.java
  Log:
  Bug fix: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2029
  
  Revision  Changes    Path
  1.5       +26 -12    xml-xerces/java/src/org/apache/xerces/utils/regex/ParserForXMLSchema.java
  
  Index: ParserForXMLSchema.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/utils/regex/ParserForXMLSchema.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ParserForXMLSchema.java	2000/06/21 00:07:00	1.4
  +++ ParserForXMLSchema.java	2001/06/18 23:18:56	1.5
  @@ -273,6 +273,7 @@
                       throw this.ex("parser.cc.5", this.offset);
                   break;                          // Exit this loop
               }
  +            
               this.next();
               if (!end) {                         // if not shorthands...
                   if (type == T_CHAR) {
  @@ -299,10 +300,15 @@
                           if (type == T_CHAR) {
                               if (rangeend == '[')  throw this.ex("parser.cc.6", this.offset-1);
                               if (rangeend == ']')  throw this.ex("parser.cc.7", this.offset-1);
  +                            if (rangeend == '-')  throw new RuntimeException("Invalid character '-' in the middle of positive character range");
                           }
                           if (type == T_BACKSOLIDUS)
                               rangeend = this.decodeEscaped();
                           this.next();
  +                        if (c > rangeend) {
  +                           throw new RuntimeException("The range end code point '"+(char) rangeend
  +                                                      + "' is less than the start code point '" +(char)c +"'");
  +                        }
                           tok.addRange(c, rangeend);
                       }
                   }
  @@ -350,6 +356,7 @@
               throw new RuntimeException("Internal Error: shorthands: \\u"+Integer.toString(ch, 16));
           }
       }
  +    
       int decodeEscaped() throws ParseException {
           if (this.read() != T_BACKSOLIDUS)  throw ex("parser.next.1", this.offset-1);
           int c = this.chardata;
  @@ -357,18 +364,25 @@
             case 'n':  c = '\n';  break; // LINE FEED U+000A
             case 'r':  c = '\r';  break; // CRRIAGE RETURN U+000D
             case 't':  c = '\t';  break; // HORIZONTAL TABULATION U+0009
  -
  -          case 'e':
  -          case 'f':
  -          case 'x':
  -          case 'u':
  -          case 'v':
  -            throw ex("parser.process.1", this.offset-2);
  -          case 'A':
  -          case 'Z':
  -          case 'z':
  -            throw ex("parser.descape.5", this.offset-2);
  -          default:
  +                        
  +          // XML Schema REC: Single Character Escape 
  +          case '\\':
  +          case '|':
  +          case '.':
  +          case '^':
  +          case '-':
  +          case '?':
  +          case '*':
  +          case '+':
  +          case '{':
  +          case '}':
  +          case '(':
  +          case ')':
  +          case '[':
  +          case ']':
  +                break;
  +         default:
  +            throw new RuntimeException("Regular expression: unrecognized character '\\"+(char)c+"' in charRange");
           }
           return c;
       }
  
  
  
  1.5       +20 -19    xml-xerces/java/src/org/apache/xerces/utils/regex/RegexParser.java
  
  Index: RegexParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/utils/regex/RegexParser.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RegexParser.java	2001/03/12 20:01:26	1.4
  +++ RegexParser.java	2001/06/18 23:18:56	1.5
  @@ -142,6 +142,7 @@
       }
   
       synchronized Token parse(String regex, int options) throws ParseException {
  +
           this.options = options;
           this.offset = 0;
           this.setContext(S_NORMAL);
  @@ -330,6 +331,7 @@
               }
               tok.addChild(this.parseTerm());
           }
  +
           return tok;
       }
   
  @@ -610,7 +612,7 @@
        * min ::= [0-9]+
        * max ::= [0-9]+
        */
  -    Token parseFactor() throws ParseException {        
  +    Token parseFactor() throws ParseException {  
           int ch = this.read();
           Token tok;
           switch (ch) {
  @@ -650,25 +652,22 @@
                   int min = 0, max = -1;
                   if (off >= this.regexlen)  break;
                   ch = this.regex.charAt(off++);
  -                if (ch != ',' && (ch < '0' || ch > '9'))  break;
  -                if (ch != ',') {                // 0-9
  -                    min = ch-'0';
  -                    while (off < this.regexlen
  -                           && (ch = this.regex.charAt(off++)) >= '0' && ch <= '9') {
  -                        min = min*10 +ch-'0';
  -                        ch = -1;
  -                    }
  -                    if (ch < 0)  break;
  +                if (ch < '0' || ch > '9')  {
  +                    throw new RuntimeException("Invalid quantifier '"+(char)ch+"' in " + regex);
                   }
  -                //if (off >= this.regexlen)  break;
  +                min = ch-'0';
  +                while (off < this.regexlen
  +                        && (ch = this.regex.charAt(off++)) >= '0' && ch <= '9') {
  +                      min = min*10 +ch-'0';
  +                      ch = -1;
  +                }
                   max = min;
  -                if (ch == ',') {
  -                    if (off >= this.regexlen
  -                        || ((ch = this.regex.charAt(off++)) < '0' || ch > '9')
  -                        && ch != '}')
  -                        break;
  +                if (ch!='}' && ch !=',' && (ch < '0' || ch > '9'))  {
  +                    throw new RuntimeException("Invalid quantifier '"+(char)ch+"' in " + regex);
  +                }
  +                else if (ch == ',') {
                       if (ch == '}') {
  -                        max = -1;           // {min,}
  +                          max = -1;           // {min,}
                       } else {
                           max = ch-'0';       // {min,max}
                           while (off < this.regexlen
  @@ -677,12 +676,14 @@
                               max = max*10 +ch-'0';
                               ch = -1;
                           }
  -                        if (ch < 0)  break;
                           //if (min > max)
                           //    throw new ParseException("parseFactor(): min > max: "+min+", "+max);
  +                    
  +                        if (ch !='}' && (ch < '0' || ch > '9'))  {
  +                            throw new RuntimeException( "Invalid quantifier '"+(char)ch+"' in" + regex);
  +                        }
                       }
                   }
  -                if (ch != '}')  break;
                                                   // off -> next of '}'
                   if (this.checkQuestion(off)) {
                       tok = Token.createNGClosure(tok);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org