mirror of
https://github.com/jquery/jquery.git
synced 2026-04-20 03:01:22 -04:00
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
This commit is contained in:
@@ -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" );
|
||||
|
||||
@@ -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=' 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 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user