Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manipulation: Properly detect HTML elements with single-character names #4125

Merged
merged 3 commits into from Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/var/rsingleTag.js
@@ -1,6 +1,7 @@
define( function() {
"use strict";

// Match a standalone tag
// rsingleTag matches a string consisting of a single HTML element with no attributes
// and captures the element's name
return ( /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i );
} );
5 changes: 4 additions & 1 deletion src/manipulation/var/rtagName.js
@@ -1,5 +1,8 @@
define( function() {
"use strict";

return ( /<([a-z][^\/\0>\x20\t\r\n\f]+)/i );
// rtagName captures the name from the first start tag in a string of HTML
// https://html.spec.whatwg.org/multipage/syntax.html#tag-open-state
// https://html.spec.whatwg.org/multipage/syntax.html#tag-name-state
return ( /<([a-z][^\/\0>\x20\t\r\n\f]*)/i );
} );
15 changes: 15 additions & 0 deletions test/unit/manipulation.js
Expand Up @@ -2772,6 +2772,21 @@ QUnit.test( "Make sure tr is not appended to the wrong tbody (gh-3439)", functio
assert.strictEqual( htmlOut, htmlExpected );
} );

QUnit.test( "Make sure tags with single-character names are found (gh-4124)", function( assert ) {
assert.expect( 1 );

var htmlOut,
htmlIn = "<p>foo<!--<td>--></p>",
$el = jQuery( "<div/>" );

$el.html( htmlIn );

// Lowercase and replace spaces to remove possible browser inconsistencies
htmlOut = $el[ 0 ].innerHTML.toLowerCase().replace( /\s/g, "" );

assert.strictEqual( htmlOut, htmlIn );
} );

QUnit.test( "Insert script with data-URI (gh-1887)", 1, function( assert ) {
Globals.register( "testFoo" );
Globals.register( "testSrcFoo" );
Expand Down