8000 [] by mgol · Pull Request #4723 · jquery/jquery · GitHub
[go: up one dir, main page]

Skip to content

[] #4723

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

Closed
wants to merge 1 commit into from
Closed

[] #4723

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/manipulation/buildFragment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import jQuery from "../core.js";
import toType from "../core/toType.js";
import isAttached from "../core/isAttached.js";
import arr from "../var/arr.js";
import document from "../var/document.js";
import rtagName from "./var/rtagName.js";
import rscriptType from "./var/rscriptType.js";
import wrapMap from "./wrapMap.js";
Expand Down Expand Up @@ -35,15 +37,17 @@ function buildFragment( elems, context, scripts, selection, ignored ) {

// Deserialize a standard representation
tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
wrap = wrapMap[ tag ] || wrapMap._default;
tmp.innerHTML = wrap[ 1 ] + jQuery.htmlPrefilter( elem ) + wrap[ 2 ];
wrap = wrapMap[ tag ] || arr;

// Descend through wrappers to the right content
j = wrap[ 0 ];
while ( j-- ) {
tmp = tmp.lastChild;
// Create wrappers & descend into them.
j = wrap.length;
while ( --j > -1 ) {
tmp.appendChild( document.createElement( wrap[ j ] ) );
tmp = tmp.firstChild;
}

tmp.innerHTML = jQuery.htmlPrefilter( elem );

jQuery.merge( nodes, tmp.childNodes );

// Remember the top-level container
Expand Down
11 changes: 4 additions & 7 deletions src/manipulation/wrapMap.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// We have to close these tags to support XHTML (#13200)
var wrapMap = {

// Table parts need to be wrapped with `<table>` or they're
// stripped to their contents when put in a div.
// XHTML parsers do not magically insert elements in the
// same way that tag soup parsers do, so we cannot shorten
// this by omitting <tbody> or other required elements.
thead: [ 1, "<table>", "</table>" ],
col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
tr: [ 2, "<table><tbody>", "</tbody></table>" ],
td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],

_default: [ 0, "", "" ]
thead: [ "table" ],
col: [ "colgroup", "table" ],
tr: [ "tbody", "table" ],
td: [ "tr", "tbody", "table" ]
};

wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
Expand Down
11 changes: 11 additions & 0 deletions test/unit/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2969,3 +2969,14 @@ QUnit.test( "Sanitized HTML doesn't get unsanitized", function( assert ) {
test( "<noembed><noembed/><img src=url404 onerror=xss(12)>" );
}
} );

QUnit.test( "Works with invalid attempts to close the table wrapper", function( assert ) {
assert.expect( 3 );

// This test case attempts to close the tags which wrap input
// based on matching done in wrapMap which should be ignored.
var elem = jQuery( "<td></td></tr></tbody></table><td></td>" );
assert.strictEqual( elem.length, 2, "Two elements created" );
assert.strictEqual( elem[ 0 ].nodeName.toLowerCase(), "td", "First element is td" );
assert.strictEqual( elem[ 1 ].nodeName.toLowerCase(), "td", "Second element is td" );
} );
0