sandygao 2003/03/24 15:31:04
Modified: java/src/org/apache/xerces/impl/xpath/regex
message.properties RegexParser.java
Log:
Fixing bugs 17417: Regex {min,max} with min > max not rejected.
Many thanks to Khaled Noaman for the patch.
Revision Changes Path
1.4 +4 -0
xml-xerces/java/src/org/apache/xerces/impl/xpath/regex/message.properties
Index: message.properties
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xpath/regex/message.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- message.properties 24 Mar 2003 23:07:45 -0000 1.3
+++ message.properties 24 Mar 2003 23:31:04 -0000 1.4
@@ -30,3 +30,7 @@
parser.descape.4=Invalid Unicode code point.
parser.descape.5=An anchor must not be here.
parser.process.1=This expression is not supported in the current option setting.
++parser.quantifier.1=Invalid quantifier. A digit is expected.
++parser.quantifier.2=Invalid quantifier. Invalid quantity or a '}' is missing.
++parser.quantifier.3=Invalid quantifier. A digit or '}' is expected.
++parser.quantifier.4=Invalid quantifier. A min quantity must be <= a max quantity.
1.7 +32 -28
xml-xerces/java/src/org/apache/xerces/impl/xpath/regex/RegexParser.java
Index: RegexParser.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xpath/regex/RegexParser.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RegexParser.java 12 Mar 2003 18:57:59 -0000 1.6
+++ RegexParser.java 24 Mar 2003 23:31:04 -0000 1.7
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -642,53 +642,57 @@
case T_PLUS: return this.processPlus(tok);
case T_QUESTION: return this.processQuestion(tok);
case T_CHAR:
- if (this.chardata == '{') {
- // this.offset -> next of '{'
- int off = this.offset;
+ if (this.chardata == '{' && this.offset < this.regexlen) {
+
+ int off = this.offset; // this.offset -> next of '{'
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';
+
+ if ((ch = this.regex.charAt(off++)) >= '0' && ch <= '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 (off >= this.regexlen) break;
+ else {
+ throw ex("parser.quantifier.1", this.offset);
+ }
+
max = min;
if (ch == ',') {
- if (off >= this.regexlen
- || ((ch = this.regex.charAt(off++)) < '0' || ch > '9')
- && ch != '}')
- break;
- if (ch == '}') {
- max = -1; // {min,}
- } else {
- max = ch-'0'; // {min,max}
+
+ if (off >= this.regexlen) {
+ throw ex("parser.quantifier.3", this.offset);
+ }
+ else if ((ch = this.regex.charAt(off++)) >= '0' && ch <= '9') {
+
+ max = ch -'0'; // {min,max}
while (off < this.regexlen
&& (ch = this.regex.charAt(off++)) >= '0'
&& ch <= '9') {
max = max*10 +ch-'0';
- ch = -1;
}
- if (ch < 0) break;
- //if (min > max)
- // throw new ParseException("parseFactor(): min > max:
"+min+", "+max);
+
+ if (min > max)
+ throw ex("parser.quantifier.4", this.offset);
+ }
+ else { // assume {min,}
+ max = -1;
}
}
- if (ch != '}') break;
- // off -> next of '}'
- if (this.checkQuestion(off)) {
+
+ if (ch != '}')
+ throw ex("parser.quantifier.2", this.offset);
+
+ if (this.checkQuestion(off)) { // off -> next of '}'
tok = Token.createNGClosure(tok);
this.offset = off+1;
} else {
tok = Token.createClosure(tok);
this.offset = off;
}
+
tok.setMin(min);
tok.setMax(max);
//System.err.println("CLOSURE: "+min+", "+max);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]