From 3bbcce68d7b8b8a7a2164a0f7a280ae9daf70b5c Mon Sep 17 00:00:00 2001 From: Timmy Willison <4timmywil@gmail.com> Date: Mon, 12 Sep 2016 12:32:02 -0400 Subject: Core: rnotwhite -> rhtmlnotwhite and jQuery.trim -> stripAndCollapse - Renames and changes rnotwhite to focus on HTML whitespace chars - Change internal use of jQuery.trim to more accurate strip and collapse - Adds tests to ensure HTML space characters are retained where valid - Doesn't add tests where the difference is inconsequential and existing tests are adequate. Fixes gh-3003 Fixes gh-3072 Close gh-3316 --- test/unit/ajax.js | 11 +++++++++++ test/unit/attributes.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-) (limited to 'test/unit') diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 5a3bd32d2..681aa463b 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -2327,6 +2327,17 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re } ); } ); + // Selector should be trimmed to avoid leading spaces (#14773) + // Selector should include any valid non-HTML whitespace (#3003) + QUnit.test( "jQuery.fn.load( URL_SELECTOR with non-HTML whitespace(#3003) )", function( assert ) { + assert.expect( 1 ); + var done = assert.async(); + jQuery( "#first" ).load( "data/test3.html #whitespace\\\\xA0 ", function() { + assert.strictEqual( jQuery( this ).children( "div" ).length, 1, "Verify that specific elements were injected" ); + done(); + } ); + } ); + QUnit.asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function( assert ) { jQuery( "#first" ).load( url( "data/name.html" ), function() { assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ), "Check if content was injected into the DOM" ); diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 771d31cb8..1284ffd18 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -657,6 +657,28 @@ QUnit.test( "removeAttr(Multi String, variable space width)", function( assert ) } ); } ); +QUnit.test( "removeAttr(Multi String, non-HTML whitespace is valid in attribute names (gh-3003)", function( assert ) { + assert.expect( 8 ); + + var div = jQuery( "
" ); + var tests = { + id: "a", + "data-\xA0": "b", + title: "c", + rel: "d" + }; + + jQuery.each( tests, function( key, val ) { + assert.equal( div.attr( key ), val, "Attribute \"" + key + "\" exists, and has a value of \"" + val + "\"" ); + } ); + + div.removeAttr( "id data-\xA0 title rel " ); + + jQuery.each( tests, function( key ) { + assert.equal( div.attr( key ), undefined, "Attribute \"" + key + "\" was removed" ); + } ); +} ); + QUnit.test( "prop(String, Object)", function( assert ) { assert.expect( 17 ); @@ -1117,7 +1139,7 @@ QUnit.test( "val(select) after form.reset() (Bug #2551)", function( assert ) { } ); QUnit.test( "select.val(space characters) (gh-2978)", function( assert ) { - assert.expect( 35 ); + assert.expect( 37 ); var $select = jQuery( "