Author: julien_viet
Date: 2010-11-27 07:27:16 -0500 (Sat, 27 Nov 2010)
New Revision: 5307
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/Parser.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RegExpAnalyser.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRegExpAnalyser.java
Log:
fix a bug in the RegExpAnalyser
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/Parser.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/Parser.java 2010-11-27
12:06:14 UTC (rev 5306)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/Parser.java 2010-11-27
12:27:16 UTC (rev 5307)
@@ -95,6 +95,13 @@
return -1;
}
+ protected final SyntaxException createSyntaxException(String msg, int start, int end)
+ {
+ StringBuilder sb = new StringBuilder(msg).append(" : ");
+ sb.append(s, 0, start).append(" ->").append(s, start,
end).append("<- ").append(s, end, s.length());
+ return new SyntaxException(sb.toString());
+ }
+
/**
* Find the closing char.
*
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java 2010-11-27
12:06:14 UTC (rev 5306)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java 2010-11-27
12:27:16 UTC (rev 5307)
@@ -161,7 +161,7 @@
case '?':
case '{':
case '|':
- throw new SyntaxException();
+ throw createSyntaxException("Was not expecting the char " + c,
index, index + 1);
case '[':
int closingBracket = findClosing(index, to, '[', ']');
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RegExpAnalyser.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RegExpAnalyser.java 2010-11-27
12:06:14 UTC (rev 5306)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RegExpAnalyser.java 2010-11-27
12:27:16 UTC (rev 5307)
@@ -133,6 +133,7 @@
sb.append("[");
visit(characterClass.getExpr());
sb.append("]");
+ quantifier = expression.getQuantifier();
}
//
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-11-27
12:06:14 UTC (rev 5306)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-11-27
12:27:16 UTC (rev 5307)
@@ -629,6 +629,12 @@
regex = "[^/]+";
}
+ // Now analyse the regexp
+// RegExpAnalyser analyser = new RegExpAnalyser();
+// analyser.process(regex);
+// String regex2 = analyser.getPattern();
+// System.out.println("" + regex + " -> " +
regex2);
+
//
builder.expr("(").expr(regex).expr(")");
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRegExpAnalyser.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRegExpAnalyser.java 2010-11-27
12:06:14 UTC (rev 5306)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRegExpAnalyser.java 2010-11-27
12:27:16 UTC (rev 5307)
@@ -59,4 +59,9 @@
assertAnalyse("(a(?:bc))", true, "(a(bc))");
assertAnalyse("(a)(?:b)", true, "(a)(b)");
}
+
+ public void testBilto()
+ {
+ assertAnalyse("[a]+", false, "[a]+");
+ }
}