🌐 AI搜索 & 代理 主页
Skip to content

Commit 979809c

Browse files
authored
Manipulation: Properly detect HTML elements with single-character names
Fixes gh-4124 Closes gh-4125
1 parent cc95204 commit 979809c

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/core/var/rsingleTag.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
define( function() {
22
"use strict";
33

4-
// Match a standalone tag
4+
// rsingleTag matches a string consisting of a single HTML element with no attributes
5+
// and captures the element's name
56
return ( /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i );
67
} );

src/manipulation/var/rtagName.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
define( function() {
22
"use strict";
33

4-
return ( /<([a-z][^\/\0>\x20\t\r\n\f]+)/i );
4+
// rtagName captures the name from the first start tag in a string of HTML
5+
// https://html.spec.whatwg.org/multipage/syntax.html#tag-open-state
6+
// https://html.spec.whatwg.org/multipage/syntax.html#tag-name-state
7+
return ( /<([a-z][^\/\0>\x20\t\r\n\f]*)/i );
58
} );

test/unit/manipulation.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,6 +2772,21 @@ QUnit.test( "Make sure tr is not appended to the wrong tbody (gh-3439)", functio
27722772
assert.strictEqual( htmlOut, htmlExpected );
27732773
} );
27742774

2775+
QUnit.test( "Make sure tags with single-character names are found (gh-4124)", function( assert ) {
2776+
assert.expect( 1 );
2777+
2778+
var htmlOut,
2779+
htmlIn = "<p>foo<!--<td>--></p>",
2780+
$el = jQuery( "<div/>" );
2781+
2782+
$el.html( htmlIn );
2783+
2784+
// Lowercase and replace spaces to remove possible browser inconsistencies
2785+
htmlOut = $el[ 0 ].innerHTML.toLowerCase().replace( /\s/g, "" );
2786+
2787+
assert.strictEqual( htmlOut, htmlIn );
2788+
} );
2789+
27752790
QUnit.test( "Insert script with data-URI (gh-1887)", 1, function( assert ) {
27762791
Globals.register( "testFoo" );
27772792
Globals.register( "testSrcFoo" );

0 commit comments

Comments
 (0)