From: Manuel Carrasco MoƱino Date: Fri, 8 Feb 2013 07:48:28 +0000 (+0100) Subject: Allow arbitrary string as parameter when adding new elements to dom. Fixes issue 128 X-Git-Tag: release-1.3.2~18^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a4da20b42d64e0c3f6f65b17979d4b0791f3034c;p=gwtquery.git Allow arbitrary string as parameter when adding new elements to dom. Fixes issue 128 --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 870e886d..16b10b92 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -424,9 +424,8 @@ public class GQuery implements Lazy { protected static GQuery cleanHtmlString(String elem, Document doc) { String tag = tagNameRegex.exec(elem).get(1); - if (tag == null) { - throw new RuntimeException("HTML snippet doesn't contain any tag"); + return $(doc.createTextNode(elem)); } if (wrapperMap == null) { diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java index f4081011..1180f5cc 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java @@ -475,6 +475,15 @@ public class GQueryCoreTestGwt extends GWTTestCase { assertEquals(1, g2.size()); assertEquals(expected, g2.toString()); } + + public void test_issue128() { + GQuery g = $(e).html("abc"); + assertEquals(g.text(), "abc"); + $("span", e).after(" "); + assertEquals(g.text(), "a b c "); + $("span", e).after("-"); + assertEquals(g.text(), "a- b- c- "); + } public void testAppendTo() { String txt = "

Greetings

Hello
Goodbye
";