From: Manolo Carrasco Date: Wed, 12 May 2010 09:53:32 +0000 (+0000) Subject: Fixed an issue which happened in domManip when it received a list of nodes with multi... X-Git-Tag: release-1.3.2~739 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8552c7691e09cad5c990e8db509669d695c99eb4;p=gwtquery.git Fixed an issue which happened in domManip when it received a list of nodes with multiple elements --- 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 0bb29fef..4e48334f 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 @@ -405,10 +405,7 @@ public class GQuery implements Lazy { } private static GQuery innerHtml(String html) { - Element div = DOM.createDiv(); - div.setInnerHTML(html); - return new GQuery( - copyNodeList((NodeList) (NodeList) div.getChildNodes())); + return $(clean(html)); } private static native String[] jsArrayToString0(JsArrayString array) /*-{ @@ -2395,7 +2392,7 @@ public class GQuery implements Lazy { } } - private JSArray clean(String elem) { + protected static JSArray clean(String elem) { String tags = elem.trim().toLowerCase(); String preWrap = "", postWrap = ""; int wrapPos = 0; @@ -2475,11 +2472,11 @@ public class GQuery implements Lazy { return domManip(clean(html), func); } - private GQuery domManip(NodeList nodes, int func) { + private GQuery domManip(NodeList nodes, int func) { for (Element e : elements()) { for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.getItem(i); - if (size() > 1) { + if (nodes.getLength() > 1) { n = n.cloneNode(true); } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java index 5732802d..03a89b86 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java @@ -44,7 +44,7 @@ public class GQueryCoreTest extends GWTTestCase { // Investigate: IE in method filter adds the attrib added="null" return s.toString().trim().toLowerCase(). replaceAll("[\r\n]", ""). - replaceAll(" ([\\w]+)=[\"]([^\"]+)[\"]", " $1=$2"). + replaceAll(" ([\\w]+)=[\"']([^\"']+)[\"']", " $1=$2"). replaceAll("\\s+\\$h=\"[^\"]+\"", ""). replaceAll(" added=[^ >]+", ""); } @@ -519,9 +519,19 @@ public class GQueryCoreTest extends GWTTestCase { assertHtmlEquals(expected, $(e).html()); $(e).html(content + wrapper); - expected - = "

Test Paragraph.

Content
"; + expected = "

Test Paragraph.

Content
"; $("*", e).wrap(""); assertHtmlEquals(expected, $(e).html()); } + + public void testDomManip() { + String content = "branchA target" + + "branchB target"; + + $(e).html(""); + $(e).append(content); + assertEquals(4, $("span", e).size()); + assertEquals(2, $("span.target", e).size()); + assertHtmlEquals(content, $(e).html()); + } }