From 7692ae419d4c19bd06a0ba01fc2af8d21035873c Mon Sep 17 00:00:00 2001 From: timmywil Date: Tue, 19 Jun 2012 11:35:45 -0400 Subject: [PATCH] When detecting html in init, ignore html characters within quotes, brackets, and parens as well as escaped characters which are valid in selectors. Fixes #11290. --- src/core.js | 3 ++- test/unit/core.js | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index c0113a190..1bf7e5603 100644 --- a/src/core.js +++ b/src/core.js @@ -41,7 +41,8 @@ var // A simple way to check for HTML strings // Prioritize #id over to avoid XSS via location.hash (#9521) - rhtmlString = /^(?:[^#<]*(<[\w\W]+>)[^>]*$)/, + // Ignore html if within quotes "" '' or brackets/parens [] () + rhtmlString = /^(?:[^#<\\]*(<[\w\W]+>)(?![^\[]*\])(?![^\(]*\))(?![^']*')(?![^"]*")[^>]*$)/, // Match a standalone tag rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, diff --git a/test/unit/core.js b/test/unit/core.js index 9950228e8..0b392adf1 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -605,7 +605,7 @@ test("isWindow", function() { }); test("jQuery('html')", function() { - expect(18); + expect( 22 ); QUnit.reset(); jQuery.foo = false; @@ -638,6 +638,11 @@ test("jQuery('html')", function() { ok( jQuery("
")[0], "Create a div with closing tag." ); ok( jQuery("
")[0], "Create a table with closing tag." ); + equal( jQuery("element[attribute='
']").length, 0, "When html is within brackets, do not recognize as html." ); + equal( jQuery("element[attribute=
]").length, 0, "When html is within brackets, do not recognize as html." ); + equal( jQuery("element:not(
)").length, 0, "When html is within parens, do not recognize as html." ); + equal( jQuery("\\").length, 0, "Ignore escaped html characters" ); + // Test very large html string #7990 var i; var li = "
  • very large html string
  • "; -- 2.39.5