You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2012/11/28 09:32:22 UTC
[Bug 54216] New: replaceregexp with backlash throws
StringIndexOutOfBoundsException
https://issues.apache.org/bugzilla/show_bug.cgi?id=54216
Bug ID: 54216
Summary: replaceregexp with backlash throws
StringIndexOutOfBoundsException
Product: Ant
Version: 1.8.3
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: Core tasks
Assignee: notifications@ant.apache.org
Reporter: emmanuel.harguindey@gmail.com
Classification: Unclassified
The follwing ant code:
<replaceregexp file="FILE.EXT" match="hello" replace="\" />
When the regexp is applied against a file regardless of its name with the text
matching 'hello' or whichever the string is selected as the match, this
Exception will be thrown:
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
It must have something to do with the backlash character escaping. The problem
disappears when applying a replace string escaped as follows:
<replaceregexp file="FILE.EXT" match="hello" replace="\\\\" />
In this case, the replacement is carried out successfully.
The bug won´t manifest itself when the text inside FILE.EXT does not match the
regular expression in the 'match' attribute.
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 54216] replaceregexp with backlash throws
StringIndexOutOfBoundsException
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54216
--- Comment #2 from Stefan Bodewig <bo...@apache.org> ---
One culprit here is java.util.regex.Matcher#appendReplacement which throws the
exception if it encounters a replacement that ends in an unescaped backslash.
I agree \\ should not be replaced by \ and the patch I'll attach fixes that,
but I'm afraid this is going to break existing builds that contain quadrupeled
backslashes to work around this long standing "feature".
Maybe just documenting what happens is better than fixing the bug, not sure.
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 54216] replaceregexp with backlash throws
StringIndexOutOfBoundsException
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54216
Jesse Glick <jg...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jglick@apache.org
Hardware|PC |All
OS| |All
--- Comment #1 from Jesse Glick <jg...@apache.org> ---
http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html#replaceAll(java.lang.String)
confirms that \ is intended to be an escape sequence. Nonetheless
Jdk14RegexpRegexp.substitute seems to be doing its own preprocessing of the
replacement string, converting \1 to $1, and I seem to recall having problems
in the past using this task to work with Windows file paths. The manual does
not appear to specify what the expected syntax of the replacement string is.
At any rate, the argument → subst conversion is clearly wrong, since \ is
converted to \ which is syntactically illegal, but \\ is converted to \ too! A
patch (including additions to RegexpTest.java and the manual) would be great.
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 54216] replaceregexp with backlash throws
StringIndexOutOfBoundsException
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54216
--- Comment #3 from Stefan Bodewig <bo...@apache.org> ---
Created attachment 31167
--> https://issues.apache.org/bugzilla/attachment.cgi?id=31167&action=edit
stop stripping backslash in regex substitution
--
You are receiving this mail because:
You are the assignee for the bug.