From: John Resig Date: Tue, 4 Sep 2007 04:34:48 +0000 (+0000) Subject: Fix for bug #1549, where the DOM conversion of and similar elements would... X-Git-Url: http://git.asbjorn.biz/?a=commitdiff_plain;h=d259ec1a93ea087d76c02009eccaa42786f737bb;p=jquery.git Fix for bug #1549, where the DOM conversion of and similar elements would fail. This forces it to work correctly in all browsers. --- diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js index 794bb5a..18fed64 100644 --- a/src/jquery/coreTest.js +++ b/src/jquery/coreTest.js @@ -12,7 +12,7 @@ test("Basic requirements", function() { }); test("$()", function() { - expect(2); + expect(5); var main = $("#main"); isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); @@ -29,6 +29,13 @@ test("$()", function() { pass = false; } ok( pass, "$('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/ + + var code = $(""); + equals( code.length, 1, "Correct number of elements generated for code" ); + var img = $(""); + equals( img.length, 1, "Correct number of elements generated for img" ); + var div = $("

"); + equals( div.length, 4, "Correct number of elements generated for div hr code b" ); }); test("isFunction", function() { diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 09e714c..038323a 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -633,6 +633,11 @@ jQuery.extend({ // Convert html string into DOM nodes if ( typeof arg == "string" ) { + // Fix "XHTML"-style tags in all browsers + arg = arg.replace(/(<(\w+)[^>]*?)\/>/g, function(m, all, tag){ + return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area)$/i)? m : all+">"; + }); + // Trim whitespace, otherwise indexOf won't work as expected var s = jQuery.trim(arg).toLowerCase(), div = doc.createElement("div"), tb = [];