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
diff --git a/pom.xml b/pom.xml
index e9ee8aa..dea1c60 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
<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>
diff --git a/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java b/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java
index 5794386..0a9f7a2 100644
--- a/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java
+++ b/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java
@@ -247,7 +247,7 @@
* @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;
}
diff --git a/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_ReplaceTest.java b/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_ReplaceTest.java
index e8c14d7..d7a3aaf 100644
--- a/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_ReplaceTest.java
+++ b/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_ReplaceTest.java
@@ -17,9 +17,16 @@
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(