From 1d61fd9407e6fbe82fe55cb0b938307aa0791f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Mon, 16 Mar 2020 21:49:29 +0100 Subject: [PATCH] Manipulation: Make jQuery.htmlPrefilter an identity function Closes gh-4642 (cherry picked from 90fed4b453a5becdb7f173d9e3c1492390a1441f) --- src/manipulation.js | 9 +-- test/data/testinit.js | 2 +- test/localfile.html | 2 +- test/unit/ajax.js | 8 +-- test/unit/attributes.js | 46 ++++++------- test/unit/basic.js | 24 +++---- test/unit/core.js | 14 ++-- test/unit/css.js | 112 +++++++++++++++---------------- test/unit/data.js | 20 +++--- test/unit/deprecated.js | 2 +- test/unit/dimensions.js | 30 ++++----- test/unit/effects.js | 22 +++--- test/unit/event.js | 26 +++---- test/unit/manipulation.js | 138 ++++++++++++++++++-------------------- test/unit/offset.js | 10 +-- test/unit/selector.js | 4 +- test/unit/traversing.js | 22 +++--- test/unit/wrap.js | 12 ++-- 18 files changed, 246 insertions(+), 257 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 017345afb..dec21ea0b 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -33,13 +33,6 @@ define( [ var - /* eslint-disable max-len */ - - // See https://github.com/eslint/eslint/issues/3229 - rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi, - - /* eslint-enable */ - // Support: IE <=10 - 11, Edge 12 - 13 only // In IE/Edge using regex groups here causes severe slowdowns. // See https://connect.microsoft.com/IE/feedback/details/1736512/ @@ -236,7 +229,7 @@ function remove( elem, selector, keepData ) { jQuery.extend( { htmlPrefilter: function( html ) { - return html.replace( rxhtmlTag, "<$1>" ); + return html; }, clone: function( elem, dataAndEvents, deepDataAndEvents ) { diff --git a/test/data/testinit.js b/test/data/testinit.js index cfbee6d73..b27ac4caa 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -251,7 +251,7 @@ this.testIframe = function( title, fileName, func, wrapper ) { } wrapper.call( QUnit, title, function( assert ) { var done = assert.async(), - $iframe = supportjQuery( "" ) .css( { position: "absolute", top: "0", left: "-600px", width: "500px" } ) .attr( { id: "qunit-fixture-iframe", src: url( fileName ) } ); diff --git a/test/localfile.html b/test/localfile.html index fbafe02cc..5a79bfec1 100644 --- a/test/localfile.html +++ b/test/localfile.html @@ -49,7 +49,7 @@ " ).appendTo( "#qunit-fixture" ); @@ -136,7 +136,7 @@ QUnit.test( "attr(String)", function( assert ) { assert.equal( $img.attr( "height" ), "53", "Retrieve height attribute on an element with display:none." ); // Check for style support - styleElem = jQuery( "
" ).appendTo( "#qunit-fixture" ).css( { + styleElem = jQuery( "
" ).appendTo( "#qunit-fixture" ).css( { background: "url(UPPERlower.gif)" } ); assert.ok( !!~styleElem.attr( "style" ).indexOf( "UPPERlower.gif" ), "Check style attribute getter" ); @@ -158,11 +158,11 @@ QUnit.test( "attr(String)", function( assert ) { $a = jQuery( "Click" ).appendTo( "#qunit-fixture" ); assert.equal( $a.attr( "onclick" ), "something()", "Retrieve ^on attribute without anonymous function wrapper." ); - assert.ok( jQuery( "
" ).attr( "doesntexist" ) === undefined, "Make sure undefined is returned when no attribute is found." ); - assert.ok( jQuery( "
" ).attr( "title" ) === undefined, "Make sure undefined is returned when no attribute is found." ); - assert.equal( jQuery( "
" ).attr( "title", "something" ).attr( "title" ), "something", "Set the title attribute." ); + assert.ok( jQuery( "
" ).attr( "doesntexist" ) === undefined, "Make sure undefined is returned when no attribute is found." ); + assert.ok( jQuery( "
" ).attr( "title" ) === undefined, "Make sure undefined is returned when no attribute is found." ); + assert.equal( jQuery( "
" ).attr( "title", "something" ).attr( "title" ), "something", "Set the title attribute." ); assert.ok( jQuery().attr( "doesntexist" ) === undefined, "Make sure undefined is returned when no element is there." ); - assert.equal( jQuery( "
" ).attr( "value" ), undefined, "An unset value on a div returns undefined." ); + assert.equal( jQuery( "
" ).attr( "value" ), undefined, "An unset value on a div returns undefined." ); assert.strictEqual( jQuery( "" ).attr( "value" ), undefined, "An unset value on a select returns undefined." ); $form = jQuery( "#form" ).attr( "enctype", "multipart/form-data" ); @@ -180,7 +180,7 @@ QUnit.test( "attr(String) on cloned elements, #9646", function( assert ) { assert.strictEqual( input.clone( true ).attr( "name", "test" )[ 0 ].name, "test", "Name attribute should be changed on cloned element" ); - div = jQuery( "
" ); + div = jQuery( "
" ); div.attr( "id" ); assert.strictEqual( div.clone( true ).attr( "id", "test" )[ 0 ].id, "test", "Id attribute should be changed on cloned element" ); @@ -299,7 +299,7 @@ QUnit.test( "attr(String, Object)", function( assert ) { $input = jQuery( "" ).attr( "checked", true ); assert.equal( $input.prop( "checked" ), true, "Setting checked updates property (verified by .prop)" ); assert.equal( $input[ 0 ].checked, true, "Setting checked updates property (verified by native property)" ); - $input = jQuery( "" ).attr( "selected", true ); assert.equal( $input.prop( "selected" ), true, "Setting selected updates property (verified by .prop)" ); assert.equal( $input[ 0 ].selected, true, "Setting selected updates property (verified by native property)" ); @@ -592,7 +592,7 @@ QUnit.test( "removeAttr(String)", function( assert ) { assert.expect( 12 ); var $first; - assert.equal( jQuery( "
" ).removeAttr( "class" ).attr( "class" ), undefined, "remove class" ); + assert.equal( jQuery( "
" ).removeAttr( "class" ).attr( "class" ), undefined, "remove class" ); assert.equal( jQuery( "#form" ).removeAttr( "id" ).attr( "id" ), undefined, "Remove id" ); assert.equal( jQuery( "#foo" ).attr( "style", "position:absolute;" ).removeAttr( "style" ).attr( "style" ), undefined, "Check removing style attribute" ); assert.equal( jQuery( "#form" ).attr( "style", "position:absolute;" ).removeAttr( "style" ).attr( "style" ), undefined, "Check removing style attribute on a form" ); @@ -692,7 +692,7 @@ QUnit.test( "prop(String, Object)", function( assert ) { assert.equal( jQuery( "#select2" ).prop( "selectedIndex" ), 3, "Check for selectedIndex attribute" ); assert.equal( jQuery( "#foo" ).prop( "nodeName" ).toUpperCase(), "DIV", "Check for nodeName attribute" ); assert.equal( jQuery( "#foo" ).prop( "tagName" ).toUpperCase(), "DIV", "Check for tagName attribute" ); - assert.equal( jQuery( "" ).prop( "selected" ), false, "Check selected attribute on disconnected element." ); assert.equal( jQuery( "#listWithTabIndex" ).prop( "tabindex" ), 5, "Check retrieving tabindex" ); jQuery( "#text1" ).prop( "readonly", true ); @@ -837,16 +837,16 @@ QUnit.test( "option.prop('selected', true) affects select.selectedIndex (gh-2732 function addOptions( $elem ) { return $elem.append( - jQuery( "" ).val( "a" ).text( "One" ), + jQuery( "" ).val( "b" ).text( "Two" ), + jQuery( "" ).val( "c" ).text( "Three" ) ) .find( "[value=a]" ).prop( "selected", true ).end() .find( "[value=c]" ).prop( "selected", true ).end(); } var $optgroup, - $select = jQuery( "" ); // Check select with options addOptions( $select ).appendTo( "#qunit-fixture" ); @@ -856,7 +856,7 @@ QUnit.test( "option.prop('selected', true) affects select.selectedIndex (gh-2732 $select.empty(); // Check select with optgroup - $optgroup = jQuery( "" ); + $optgroup = jQuery( "" ); addOptions( $optgroup ).appendTo( $select ); $select.find( "[value=b]" ).prop( "selected", true ); @@ -970,7 +970,7 @@ QUnit.test( "val()", function( assert ) { assert.equal( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" ); assert.equal( $button.val( "baz" ).html(), "text", "Setting the value does not change innerHTML" ); - assert.equal( jQuery( "" ).val( "test" ).attr( "value" ), "test", "Setting value sets the value attribute" ); } ); QUnit.test( "val() with non-matching values on dropdown list", function( assert ) { @@ -1029,7 +1029,7 @@ var testVal = function( valueObj, assert ) { assert.equal( document.getElementById( "text1" ).value, "", "Check for modified (via val(null)) value of input element" ); var j, - $select = jQuery( "" ), + $select = jQuery( "" ), $select1 = jQuery( "#select1" ); $select1.val( valueObj( "3" ) ); @@ -1145,7 +1145,7 @@ QUnit.test( "val(select) after form.reset() (Bug #2551)", function( assert ) { QUnit.test( "select.val(space characters) (gh-2978)", function( assert ) { assert.expect( 37 ); - var $select = jQuery( "" ).appendTo( "#qunit-fixture" ), spaces = { "\\t": { html: " ", @@ -1230,7 +1230,7 @@ var testAddClass = function( valueObj, assert ) { j.addClass( valueObj( "asdf" ) ); assert.ok( j.hasClass( "asdf" ), "Check node,textnode,comment for addClass" ); - div = jQuery( "
" ); + div = jQuery( "
" ); div.addClass( valueObj( "test" ) ); assert.equal( div.attr( "class" ), "test", "Make sure there's no extra whitespace." ); @@ -1669,9 +1669,9 @@ QUnit.test( "coords returns correct values in IE6/IE7, see #10828", function( as assert.expect( 1 ); var area, - map = jQuery( "" ); + map = jQuery( "" ); - area = map.html( "a" ).find( "area" ); + area = map.html( "a" ).find( "area" ); assert.equal( area.attr( "coords" ), "0,0,0,0", "did not retrieve coords correctly" ); } ); @@ -1679,7 +1679,7 @@ QUnit.test( "should not throw at $(option).val() (#14686)", function( assert ) { assert.expect( 1 ); try { - jQuery( "" ).val(); assert.ok( true ); } catch ( _ ) { assert.ok( false ); diff --git a/test/unit/basic.js b/test/unit/basic.js index 9cb7d25be..aadf36fa3 100644 --- a/test/unit/basic.js +++ b/test/unit/basic.js @@ -36,7 +36,7 @@ QUnit.test( "ajax", function( assert ) { QUnit.test( "attributes", function( assert ) { assert.expect( 6 ); - var a = jQuery( "" ).appendTo( "#qunit-fixture" ), + var a = jQuery( "" ).appendTo( "#qunit-fixture" ), input = jQuery( "" ).appendTo( "#qunit-fixture" ); assert.strictEqual( a.attr( "foo", "bar" ).attr( "foo" ), "bar", ".attr getter/setter" ); @@ -56,7 +56,7 @@ if ( jQuery.css ) { QUnit.test( "css", function( assert ) { assert.expect( 1 ); - var div = jQuery( "
" ).appendTo( "#qunit-fixture" ); + var div = jQuery( "
" ).appendTo( "#qunit-fixture" ); assert.strictEqual( div.css( "width", "50px" ).css( "width" ), "50px", ".css getter/setter" ); } ); @@ -66,7 +66,7 @@ if ( jQuery.fn.show && jQuery.fn.hide ) { QUnit.test( "show/hide", function( assert ) { assert.expect( 2 ); - var div = jQuery( "
" ).appendTo( "#qunit-fixture" ); + var div = jQuery( "
" ).appendTo( "#qunit-fixture" ); div.hide(); assert.strictEqual( div.css( "display" ), "none", "div hidden" ); @@ -126,7 +126,7 @@ QUnit.test( "core", function( assert ) { QUnit.test( "data", function( assert ) { assert.expect( 4 ); - var elem = jQuery( "
" ).appendTo( "#qunit-fixture" ); + var elem = jQuery( "
" ).appendTo( "#qunit-fixture" ); assert.ok( !jQuery.hasData( elem[ 0 ] ), "jQuery.hasData - false" ); assert.strictEqual( elem.data( "a", "b" ).data( "a" ), "b", ".data getter/setter" ); @@ -138,7 +138,7 @@ QUnit.test( "dimensions", function( assert ) { assert.expect( 3 ); var elem = jQuery( - "
" + "
" ).appendTo( "#qunit-fixture" ); assert.strictEqual( elem.width( 50 ).width(), 50, ".width getter/setter" ); @@ -149,7 +149,7 @@ QUnit.test( "dimensions", function( assert ) { QUnit.test( "event", function( assert ) { assert.expect( 1 ); - var elem = jQuery( "
" ).appendTo( "#qunit-fixture" ); + var elem = jQuery( "
" ).appendTo( "#qunit-fixture" ); elem .on( "click", function() { @@ -168,12 +168,12 @@ QUnit.test( "manipulation", function( assert ) { var child, elem1 = jQuery( "
" ).appendTo( "#qunit-fixture" ), - elem2 = jQuery( "
" ).appendTo( "#qunit-fixture" ); + elem2 = jQuery( "
" ).appendTo( "#qunit-fixture" ); assert.strictEqual( elem1.text( "foo" ).text(), "foo", ".html getter/setter" ); assert.strictEqual( - elem1.html( "" ).html(), + elem1.html( "" ).html(), "", ".html getter/setter" ); @@ -182,8 +182,8 @@ QUnit.test( "manipulation", function( assert ) { assert.strictEqual( elem1.prepend( elem2 )[ 0 ].childNodes[ 0 ], elem2[ 0 ], ".prepend" ); child = elem1.find( "span" ); - child.after( "" ); - child.before( "" ); + child.after( "" ); + child.before( "" ); assert.strictEqual( elem1.html(), @@ -197,8 +197,8 @@ QUnit.test( "manipulation", function( assert ) { QUnit[ /jsdom\//.test( navigator.userAgent ) ? "skip" : "test" ]( "offset", function( assert ) { assert.expect( 3 ); - var parent = jQuery( "
" ).appendTo( "#qunit-fixture" ), - elem = jQuery( "
" ).appendTo( parent ); + var parent = jQuery( "
" ).appendTo( "#qunit-fixture" ), + elem = jQuery( "
" ).appendTo( parent ); assert.strictEqual( elem.offset().top, 25, ".offset getter" ); assert.strictEqual( elem.position().top, 5, ".position getter" ); diff --git a/test/unit/core.js b/test/unit/core.js index 1c3dc7365..b31ee9e2b 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -23,9 +23,9 @@ QUnit.test( "jQuery()", function( assert ) { var elem, i, obj = jQuery( "div" ), - code = jQuery( "" ), + code = jQuery( "" ), img = jQuery( "" ), - div = jQuery( "

" ), + div = jQuery( "

" ), exec = false, expected = 23, attrObj = { @@ -113,7 +113,7 @@ QUnit.test( "jQuery()", function( assert ) { elem = jQuery( "\n\nworld" )[ 0 ]; assert.equal( elem.nodeName.toLowerCase(), "em", "leading newlines" ); - elem = jQuery( "
", attrObj ); + elem = jQuery( "
", attrObj ); if ( jQuery.fn.width ) { assert.equal( elem[ 0 ].style.width, "10px", "jQuery() quick setter width" ); @@ -458,7 +458,7 @@ QUnit.test( "jQuery('html')", function( assert ) { assert.ok( jQuery( "" )[ 0 ], "Creating a link" ); - assert.ok( !jQuery( "" )[ 0 ].parentNode, "Create a script" ); assert.ok( jQuery( "" ).attr( "type", "hidden" ), "Create an input and set the type." ); @@ -526,8 +526,8 @@ QUnit.test( "jQuery('massive html #7990')", function( assert ) { QUnit.test( "jQuery('html', context)", function( assert ) { assert.expect( 1 ); - var $div = jQuery( "
" )[ 0 ], - $span = jQuery( "", $div ); + var $div = jQuery( "
" )[ 0 ], + $span = jQuery( "", $div ); assert.equal( $span.length, 1, "verify a span created with a div context works, #1763" ); } ); @@ -1356,7 +1356,7 @@ QUnit.test( "jQuery.parseHTML", function( assert ) { assert.equal( jQuery.parseHTML( "text" )[ 0 ].nodeType, 3, "Parsing text returns a text node" ); assert.equal( jQuery.parseHTML( "\t
" )[ 0 ].nodeValue, "\t", "Preserve leading whitespace" ); - assert.equal( jQuery.parseHTML( "
" )[ 0 ].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" ); + assert.equal( jQuery.parseHTML( "
" )[ 0 ].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" ); html = jQuery.parseHTML( "
test div
" ); diff --git a/test/unit/css.js b/test/unit/css.js index 190e6d169..c6a17a7c8 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -13,7 +13,7 @@ QUnit.test( "css(String|Hash)", function( assert ) { assert.notEqual( $child.css( "width" ), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" ); assert.notEqual( $child.css( "height" ), "20px", "Retrieving a height percentage on the child of a hidden div returns percentage" ); - div = jQuery( "
" ); + div = jQuery( "
" ); // These should be "auto" (or some better value) // temporarily provide "0px" for backwards compat @@ -25,7 +25,7 @@ QUnit.test( "css(String|Hash)", function( assert ) { assert.equal( div.css( "width" ), "4px", "Width on disconnected node." ); assert.equal( div.css( "height" ), "4px", "Height on disconnected node." ); - div2 = jQuery( "
" ).appendTo( "body" ); assert.equal( div2.find( "input" ).css( "height" ), "20px", "Height on hidden input." ); assert.equal( div2.find( "textarea" ).css( "height" ), "20px", "Height on hidden textarea." ); @@ -42,7 +42,7 @@ QUnit.test( "css(String|Hash)", function( assert ) { assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) ), 0, "Test negative width set to 0" ); assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) ), 0, "Test negative height set to 0" ); - assert.equal( jQuery( "
" ).css( "display" ), "none", "Styles on disconnected nodes" ); + assert.equal( jQuery( "
" ).css( "display" ), "none", "Styles on disconnected nodes" ); jQuery( "#floatTest" ).css( { "float": "right" } ); assert.equal( jQuery( "#floatTest" ).css( "float" ), "right", "Modified CSS float using \"float\": Assert float is right" ); @@ -111,7 +111,7 @@ QUnit.test( "css(String|Hash)", function( assert ) { assert.strictEqual( child.css( "x-fake" ), undefined, "Make sure undefined is returned from css(nonexistent)." ); - div = jQuery( "
" ).css( { position: "absolute", "z-index": 1000 } ).appendTo( "#qunit-fixture" ); + div = jQuery( "
" ).css( { position: "absolute", "z-index": 1000 } ).appendTo( "#qunit-fixture" ); assert.strictEqual( div.css( "z-index" ), "1000", "Make sure that a string z-index is returned from css('z-index') (#14432)." ); } ); @@ -275,10 +275,10 @@ QUnit.test( "css() mismatched relative values with bounded styles (gh-2144)", fu assert.expect( 1 ); var right, - $container = jQuery( "
" ) + $container = jQuery( "
" ) .css( { position: "absolute", width: "400px", fontSize: "4px" } ) .appendTo( "#qunit-fixture" ), - $el = jQuery( "
" ) + $el = jQuery( "
" ) .css( { position: "absolute", left: "50%", right: "50%" } ) .appendTo( $container ); @@ -574,7 +574,7 @@ QUnit.test( "show/hide detached nodes", function( assert ) { assert.equal( div.css( "display" ), "none", "A shown-while-detached div inside a visible div can be hidden by the CSS cascade" ); - span = jQuery( "