Author: fschumacher
Date: Sat Apr 29 12:18:36 2017
New Revision: 1793191
URL: http://svn.apache.org/viewvc?rev=1793191&view=rev
Log:
Endless loop in JOrphanUtils#replaceAllWithRegex when regex is contained in replacement
Bugzilla Id: 61054
Modified:
jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
jmeter/trunk/test/src/org/apache/jorphan/util/TestJorphanUtils.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java?rev=1793191&r1=1793190&r2=1793191&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java Sat Apr 29 12:18:36
2017
@@ -632,23 +632,18 @@ public final class JOrphanUtils {
java.util.regex.Pattern pattern = caseSensitive ?
java.util.regex.Pattern.compile(regex) :
java.util.regex.Pattern.compile(regex, java.util.regex.Pattern.CASE_INSENSITIVE);
- String newText = source;
final String replacementQuoted = Matcher.quoteReplacement(replacement);
- Matcher matcher = pattern.matcher(newText);
+ Matcher matcher = pattern.matcher(source);
int totalReplaced = 0;
- while(true) {
- String previousText = newText;
- newText = matcher.replaceFirst(replacementQuoted);
- matcher = pattern.matcher(newText);
- if(newText.equals(previousText)) {
- break;
- } else {
- totalReplaced++;
- }
+ StringBuffer result = new StringBuffer(); // NOSONAR Matcher#appendReplacement needs
a StringBuffer
+ while(matcher.find()) {
+ matcher.appendReplacement(result, replacementQuoted);
+ totalReplaced++;
}
+ matcher.appendTail(result);
return new Object[]{
- newText,
+ result.toString(),
totalReplaced
};
}
Modified: jmeter/trunk/test/src/org/apache/jorphan/util/TestJorphanUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jorphan/util/TestJorphanUtils.java?rev=1793191&r1=1793190&r2=1793191&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jorphan/util/TestJorphanUtils.java (original)
+++ jmeter/trunk/test/src/org/apache/jorphan/util/TestJorphanUtils.java Sat Apr 29 12:18:36
2017
@@ -298,6 +298,13 @@ public class TestJorphanUtils {
}
@Test
+ public void testReplaceAllWithRegexWithSearchValueContainedInReplaceValue() {
+ // Bug 61054
+ Assert.assertArrayEquals(new Object[] { "abcd", 1 },
+ JOrphanUtils.replaceAllWithRegex("abc", "abc", "abcd", true));
+ }
+
+ @Test
public void testReplaceAllWithRegex() {
Assert.assertArrayEquals(new Object[] {"toto", 0},
JOrphanUtils.replaceAllWithRegex("toto","ti", "ta", true));
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1793191&r1=1793190&r2=1793191&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Apr 29 12:18:36 2017
@@ -162,12 +162,13 @@ Summary
<h3>Report / Dashboard</h3>
<ul>
</ul>
-
+
<h3>General</h3>
<ul>
<li><bug>60994</bug>Fix some typo in comments or log messages. <pr>289</pr>
and <pr>290</pr></li>
<li><bug>61011</bug>Replace occurrences count is not correct (Path
and Host replacement are counted twice)</li>
<li><bug>61026</bug>Cannot run program "keytool": CreateProcess error=2
when starting JMeter 3.2 in gui mode</li>
+ <li><bug>61054</bug>Endless loop in JOrphanUtils#replaceAllWithRegex
when regex is contained in replacement</li>
</ul>
<!-- =================== Thanks =================== -->
|