You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/09/27 13:50:53 UTC
svn commit: r1390954 - in /commons/proper/lang/trunk/src: changes/changes.xml
main/java/org/apache/commons/lang3/time/FastDateParser.java
Author: sebb
Date: Thu Sep 27 11:50:52 2012
New Revision: 1390954
URL: http://svn.apache.org/viewvc?rev=1390954&view=rev
Log:
LANG-830 FastDateParser could use \Q \E to quote regexes
Modified:
commons/proper/lang/trunk/src/changes/changes.xml
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1390954&r1=1390953&r2=1390954&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml Thu Sep 27 11:50:52 2012
@@ -24,6 +24,7 @@
<release version="3.2" date="TBA" description="Next release">
<action issue="LANG-832" type="fix">FastDateParser does not handle unterminated quotes correctly</action>
<action issue="LANG-831" type="fix">FastDateParser does not handle white-space properly</action>
+ <action issue="LANG-830" type="fix">FastDateParser could use \Q \E to quote regexes</action>
<action issue="LANG-828" type="fix">FastDateParser does not handle non-Gregorian calendars properly</action>
<action issue="LANG-826" type="fix">FastDateParser does not handle non-ASCII digits correctly</action>
<action issue="LANG-825" type="add">Create StrBuilder APIs similar to String.format(String, Object...)</action>
Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java?rev=1390954&r1=1390953&r2=1390954&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDateParser.java Thu Sep 27 11:50:52 2012
@@ -297,6 +297,7 @@ public class FastDateParser implements D
* @return The <code>StringBuilder</code>
*/
private static StringBuilder escapeRegex(StringBuilder regex, String value, boolean unquote) {
+ regex.append("\\Q");
for(int i= 0; i<value.length(); ++i) {
char c= value.charAt(i);
switch(c) {
@@ -308,24 +309,28 @@ public class FastDateParser implements D
c= value.charAt(i);
}
break;
- case '?':
- case '[':
- case ']':
- case '(':
- case ')':
- case '{':
- case '}':
case '\\':
- case '|':
- case '*':
- case '+':
- case '^':
- case '$':
- case '.':
- regex.append('\\');
+ if(++i==value.length()) {
+ break;
+ }
+ /*
+ * If we have found \E, we replace it with \E\\E\Q, i.e. we stop the quoting,
+ * quote the \ in \E, then restart the quoting.
+ *
+ * Otherwise we just output the two characters.
+ * In each case the initial \ needs to be output and the final char is done at the end
+ */
+ regex.append(c); // we always want the original \
+ c = value.charAt(i); // Is it followed by E ?
+ if (c == 'E') { // \E detected
+ regex.append("E\\\\E\\"); // see comment above
+ c = 'Q'; // appended below
+ }
+ break;
}
regex.append(c);
}
+ regex.append("\\E");
return regex;
}