Browse Source

fix for bug 20306 - regex handling of $ in replace string

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274633 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 22 years ago
parent
commit
4e2a4f9c95
4 changed files with 24 additions and 3 deletions
  1. +9
    -0
      src/etc/testcases/filters/tokenfilter.xml
  2. +4
    -1
      src/main/org/apache/tools/ant/util/regexp/JakartaOroRegexp.java
  3. +4
    -1
      src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexp.java
  4. +7
    -1
      src/testcases/org/apache/tools/ant/filters/TokenFilterTest.java

+ 9
- 0
src/etc/testcases/filters/tokenfilter.xml View File

@@ -181,6 +181,15 @@
</concat>
</target>

<target name="dollermatch">
<concat>
@hello@
<filterchain>
<replaceregex pattern="@([^@]*)@" replace="${\1}"/>
</filterchain>
</concat>
</target>

<!-- need to check for existance of regex -->
<target name="containsregex">
<concat destfile="result/input">


+ 4
- 1
src/main/org/apache/tools/ant/util/regexp/JakartaOroRegexp.java View File

@@ -76,7 +76,10 @@ public class JakartaOroRegexp extends JakartaOroMatcher implements Regexp {
StringBuffer subst = new StringBuffer();
for (int i = 0; i < argument.length(); i++) {
char c = argument.charAt(i);
if (c == '\\') {
if (c == '$') {
subst.append('\\');
subst.append('$');
} else if (c == '\\') {
if (++i < argument.length()) {
c = argument.charAt(i);
int value = Character.digit(c, 10);


+ 4
- 1
src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexp.java View File

@@ -83,7 +83,10 @@ public class Jdk14RegexpRegexp extends Jdk14RegexpMatcher implements Regexp {
StringBuffer subst = new StringBuffer();
for (int i = 0; i < argument.length(); i++) {
char c = argument.charAt(i);
if (c == '\\') {
if (c == '$') {
subst.append('\\');
subst.append('$');
} else if (c == '\\') {
if (++i < argument.length()) {
c = argument.charAt(i);
int value = Character.digit(c, 10);


+ 7
- 1
src/testcases/org/apache/tools/ant/filters/TokenFilterTest.java View File

@@ -77,7 +77,7 @@ public class TokenFilterTest extends BuildFileTest {
}

public void tearDown() {
//executeTarget("cleanup");
executeTarget("cleanup");
}

/** make sure tokenfilter exists */
@@ -147,6 +147,12 @@ public class TokenFilterTest extends BuildFileTest {
assertStringContains(contents, "world world world world");
}

public void testHandleDollerMatch() throws IOException {
if (! hasRegex("testFilterReplaceRegex"))
return;
executeTarget("dollermatch");
}
public void testTrimFile() throws IOException {
String contents = getFileString(
"trimfile", "result/trimfile");


Loading…
Cancel
Save