]> source.dussan.org Git - gwtquery.git/commitdiff
Allow arbitrary string as parameter when adding new elements to dom. Fixes issue 128
authorManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>
Fri, 8 Feb 2013 07:48:28 +0000 (08:48 +0100)
committerManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>
Fri, 8 Feb 2013 07:48:28 +0000 (08:48 +0100)
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java

index 870e886d5d3ffee1b5a6fdb56f67ce52fa15c867..16b10b92bc2caaf1842b402fd705611c15f8ba3a 100644 (file)
@@ -424,9 +424,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
   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) {
index f4081011178c3f62b3eb19962ca629b80b431d05..1180f5ccfb29b5f29f8c9d28f6e507a2ecd4ef50 100644 (file)
@@ -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("<span>a</span><span>b</span><span>c</span>");
+    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 = "<h2>Greetings</h2><div class='container'><div class='inner'>Hello</div><div class='inner'>Goodbye</div></div>";