Skip to content

Commit 7692ae4

Browse files
committed
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.
1 parent 868a9ce commit 7692ae4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/core.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ var
4141

4242
// A simple way to check for HTML strings
4343
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
44-
rhtmlString = /^(?:[^#<]*(<[\w\W]+>)[^>]*$)/,
44+
// Ignore html if within quotes "" '' or brackets/parens [] ()
45+
rhtmlString = /^(?:[^#<\\]*(<[\w\W]+>)(?![^\[]*\])(?![^\(]*\))(?![^']*')(?![^"]*")[^>]*$)/,
4546

4647
// Match a standalone tag
4748
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,

test/unit/core.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ test("isWindow", function() {
605605
});
606606

607607
test("jQuery('html')", function() {
608-
expect(18);
608+
expect( 22 );
609609

610610
QUnit.reset();
611611
jQuery.foo = false;
@@ -638,6 +638,11 @@ test("jQuery('html')", function() {
638638
ok( jQuery("<div></div>")[0], "Create a div with closing tag." );
639639
ok( jQuery("<table></table>")[0], "Create a table with closing tag." );
640640

641+
equal( jQuery("element[attribute='<div></div>']").length, 0, "When html is within brackets, do not recognize as html." );
642+
equal( jQuery("element[attribute=<div></div>]").length, 0, "When html is within brackets, do not recognize as html." );
643+
equal( jQuery("element:not(<div></div>)").length, 0, "When html is within parens, do not recognize as html." );
644+
equal( jQuery("\\<div\\>").length, 0, "Ignore escaped html characters" );
645+
641646
// Test very large html string #7990
642647
var i;
643648
var li = "<li>very large html string</li>";

0 commit comments

Comments
 (0)