From 979809c5a80aaf26bf7e3406a2e361e809f9b132 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Fri, 13 Jul 2018 00:35:08 -0400 Subject: [PATCH] Manipulation: Properly detect HTML elements with single-character names Fixes gh-4124 Closes gh-4125 --- src/core/var/rsingleTag.js | 3 ++- src/manipulation/var/rtagName.js | 5 ++++- test/unit/manipulation.js | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/core/var/rsingleTag.js b/src/core/var/rsingleTag.js index 4d6e8a0ac..340b80db0 100644 --- a/src/core/var/rsingleTag.js +++ b/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 ); } ); diff --git a/src/manipulation/var/rtagName.js b/src/manipulation/var/rtagName.js index d565dd3de..7435620c1 100644 --- a/src/manipulation/var/rtagName.js +++ b/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 ); } ); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 660dad773..28a62fe0b 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -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 = "

foo

", + $el = jQuery( "
" ); + + $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" ); -- 2.39.5