aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorTimmy Willison <4timmywil@gmail.com>2016-09-12 12:32:02 -0400
committerTimmy Willison <4timmywil@gmail.com>2016-09-15 10:40:27 -0400
commit3bbcce68d7b8b8a7a2164a0f7a280ae9daf70b5c (patch)
treea65aefeef8aa62ff092254dcd5b1f2c256dc82ea /test/unit
parent2d4f53416e5f74fa98e0c1d66b6f3c285a12f0ce (diff)
downloadjquery-3bbcce68d7b8b8a7a2164a0f7a280ae9daf70b5c.tar.gz
jquery-3bbcce68d7b8b8a7a2164a0f7a280ae9daf70b5c.zip
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
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/ajax.js11
-rw-r--r--test/unit/attributes.js50
2 files changed, 58 insertions, 3 deletions
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( "<div id='a' data-\xA0='b' title='c' rel='d'></div>" );
+ 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( "<select/>" ).appendTo( "#qunit-fixture" ),
spaces = {
@@ -1168,13 +1190,17 @@ QUnit.test( "select.val(space characters) (gh-2978)", function( assert ) {
html += "<option>" + value + "text</option>";
$select.html( html );
- $select.val( "text" );
- assert.equal( $select.val(), "text", "Value with space character at beginning or end is stripped (" + key + ") selected (text)" );
if ( /^\\u/.test( key ) ) {
+ $select.val( val + "text" );
+ assert.equal( $select.val(), val + "text", "Value with non-HTML space character at beginning is not stripped (" + key + ") selected (" + key + "text)" );
$select.val( "te" + val + "xt" );
assert.equal( $select.val(), "te" + val + "xt", "Value with non-space whitespace character (" + key + ") in the middle selected (text)" );
+ $select.val( "text" + val );
+ assert.equal( $select.val(), "text" + val, "Value with non-HTML space character at end is not stripped (" + key + ") selected (text" + key + ")" );
} else {
+ $select.val( "text" );
+ assert.equal( $select.val(), "text", "Value with HTML space character at beginning or end is stripped (" + key + ") selected (text)" );
$select.val( "te xt" );
assert.equal( $select.val(), "te xt", "Value with space character (" + key + ") in the middle selected (text)" );
}
@@ -1541,6 +1567,24 @@ QUnit.test( "addClass, removeClass, hasClass on many elements", function( assert
"Did not find a class when not present" );
} );
+QUnit.test( "addClass, removeClass, hasClass on elements with classes with non-HTML whitespace (gh-3072, gh-3003)", function( assert ) {
+ assert.expect( 9 );
+
+ var $elem = jQuery( "<div class='&#xA0;test'></div>" );
+
+ function testMatches() {
+ assert.ok( $elem.is( ".\\A0 test" ), "Element matches with collapsed space" );
+ assert.ok( $elem.is( ".\\A0test" ), "Element matches with non-breaking space" );
+ assert.ok( $elem.hasClass( "\xA0test" ), "Element has class with non-breaking space" );
+ }
+
+ testMatches();
+ $elem.addClass( "foo" );
+ testMatches();
+ $elem.removeClass( "foo" );
+ testMatches();
+} );
+
QUnit.test( "contents().hasClass() returns correct values", function( assert ) {
assert.expect( 2 );