Fix bug in SafeHtml.replaceAll and bump to 1.3.4

Joining an empty list produces the pattern (), which matches an infinite
number of times, which is bad. Just short-circuit instead.

Change-Id: I84266d1c82de9833a6477e39ecee99df4439a491
This commit is contained in:
Dave Borowitz
2013-04-09 20:06:31 -07:00
parent 14bee96f6e
commit d4c0d950f8
3 changed files with 9 additions and 2 deletions

View File

@@ -21,7 +21,7 @@ limitations under the License.
<groupId>gwtexpui</groupId>
<artifactId>gwtexpui</artifactId>
<packaging>jar</packaging>
<version>1.3.4-SNAPSHOT</version>
<version>1.3.4</version>
<name>gwtexpui</name>
<description>Extended UI tools for GWT</description>
<url>https://gerrit.googlesource.com/gwtexpui</url>

View File

@@ -247,7 +247,7 @@ public abstract class SafeHtml {
* @return a new string, after the replacements have been made.
*/
public <T> SafeHtml replaceAll(List<? extends FindReplace> findReplaceList) {
if (findReplaceList == null) {
if (findReplaceList == null || findReplaceList.isEmpty()) {
return this;
}

View File

@@ -17,9 +17,16 @@ package com.google.gwtexpui.safehtml.client;
import junit.framework.TestCase;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class SafeHtml_ReplaceTest extends TestCase {
public void testReplaceEmpty() {
SafeHtml o = html("A\nissue42\nB");
assertSame(o, o.replaceAll(null));
assertSame(o, o.replaceAll(Collections.<FindReplace> emptyList()));
}
public void testReplaceOneLink() {
SafeHtml o = html("A\nissue 42\nB");
SafeHtml n = o.replaceAll(repls(