From f6c034b007eecf2e9828eb4ac004b3a86c57e0f5 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Thu, 19 Feb 2004 21:14:16 +0000 Subject: [PATCH] TokenFilter.ReplaceString only replaced the first occurrence. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276118 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 ++ src/etc/testcases/filters/tokenfilter.xml | 20 +++++++++++++++++++ .../apache/tools/ant/filters/TokenFilter.java | 2 +- .../tools/ant/filters/TokenFilterTest.java | 8 ++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/WHATSNEW b/WHATSNEW index dcbda4b6d..63d9dc505 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -21,6 +21,8 @@ Fixed bugs: * macrodef @@ escaping was broken. Bugzilla Report 27069. +* replacestring tokenfilter only replaced the first occurrence. + Other changes: -------------- diff --git a/src/etc/testcases/filters/tokenfilter.xml b/src/etc/testcases/filters/tokenfilter.xml index ddfa57eba..86f5b9250 100644 --- a/src/etc/testcases/filters/tokenfilter.xml +++ b/src/etc/testcases/filters/tokenfilter.xml @@ -67,6 +67,15 @@ + + + foo foo foo + + + + + + This is a number @@ -134,6 +143,17 @@ + + + foo foo foo + + + + + + + + this is a line contains foo diff --git a/src/main/org/apache/tools/ant/filters/TokenFilter.java b/src/main/org/apache/tools/ant/filters/TokenFilter.java index a1f234b10..f195ca62f 100644 --- a/src/main/org/apache/tools/ant/filters/TokenFilter.java +++ b/src/main/org/apache/tools/ant/filters/TokenFilter.java @@ -527,7 +527,7 @@ public class TokenFilter extends BaseFilterReader // search again start = found + from.length(); - found = line.indexOf(line, start); + found = line.indexOf(from, start); } // write the remaining characters diff --git a/src/testcases/org/apache/tools/ant/filters/TokenFilterTest.java b/src/testcases/org/apache/tools/ant/filters/TokenFilterTest.java index d3607eea8..e35e3f871 100644 --- a/src/testcases/org/apache/tools/ant/filters/TokenFilterTest.java +++ b/src/testcases/org/apache/tools/ant/filters/TokenFilterTest.java @@ -82,6 +82,10 @@ public class TokenFilterTest extends BuildFileTest { "this is the moon"); } + public void testReplaceStrings() throws IOException { + expectLogContaining("replacestrings", "bar bar bar"); + } + public void testContainsString() throws IOException { String contents = getFileString( "containsstring", "result/containsstring"); @@ -139,6 +143,10 @@ public class TokenFilterTest extends BuildFileTest { assertStringContains(contents, "This is the moon"); } + public void testFilterReplaceStrings() throws IOException { + expectLogContaining("filterreplacestrings", "bar bar bar"); + } + public void testContainsRegex() throws IOException { if (! hasRegex("testContainsRegex")) return;