From a4da20b42d64e0c3f6f65b17979d4b0791f3034c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Fri, 8 Feb 2013 08:48:28 +0100 Subject: [PATCH] Allow arbitrary string as parameter when adding new elements to dom. Fixes issue 128 --- .../main/java/com/google/gwt/query/client/GQuery.java | 3 +-- .../com/google/gwt/query/client/GQueryCoreTestGwt.java | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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
"; -- 2.39.5