diff options
author | Timmy Willison <4timmywil@gmail.com> | 2016-09-12 12:32:02 -0400 |
---|---|---|
committer | Timmy Willison <4timmywil@gmail.com> | 2016-09-15 10:40:27 -0400 |
commit | 3bbcce68d7b8b8a7a2164a0f7a280ae9daf70b5c (patch) | |
tree | a65aefeef8aa62ff092254dcd5b1f2c256dc82ea /src/attributes | |
parent | 2d4f53416e5f74fa98e0c1d66b6f3c285a12f0ce (diff) | |
download | jquery-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 'src/attributes')
-rw-r--r-- | src/attributes/attr.js | 9 | ||||
-rw-r--r-- | src/attributes/classes.js | 29 | ||||
-rw-r--r-- | src/attributes/val.js | 8 |
3 files changed, 22 insertions, 24 deletions
diff --git a/src/attributes/attr.js b/src/attributes/attr.js index 5d85f4f19..2d9c76feb 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -2,9 +2,9 @@ define( [ "../core", "../core/access", "./support", - "../var/rnotwhite", + "../var/rnothtmlwhite", "../selector" -], function( jQuery, access, support, rnotwhite ) { +], function( jQuery, access, support, rnothtmlwhite ) { "use strict"; @@ -89,7 +89,10 @@ jQuery.extend( { removeAttr: function( elem, value ) { var name, i = 0, - attrNames = value && value.match( rnotwhite ); + + // Attribute names can contain non-HTML whitespace characters + // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 + attrNames = value && value.match( rnothtmlwhite ); if ( attrNames && elem.nodeType === 1 ) { while ( ( name = attrNames[ i++ ] ) ) { diff --git a/src/attributes/classes.js b/src/attributes/classes.js index 2e8a8caba..23b4cd6af 100644 --- a/src/attributes/classes.js +++ b/src/attributes/classes.js @@ -1,14 +1,13 @@ define( [ "../core", - "../var/rnotwhite", + "../core/stripAndCollapse", + "../var/rnothtmlwhite", "../data/var/dataPriv", "../core/init" -], function( jQuery, rnotwhite, dataPriv ) { +], function( jQuery, stripAndCollapse, rnothtmlwhite, dataPriv ) { "use strict"; -var rclass = /[\t\r\n\f]/g; - function getClass( elem ) { return elem.getAttribute && elem.getAttribute( "class" ) || ""; } @@ -25,12 +24,11 @@ jQuery.fn.extend( { } if ( typeof value === "string" && value ) { - classes = value.match( rnotwhite ) || []; + classes = value.match( rnothtmlwhite ) || []; while ( ( elem = this[ i++ ] ) ) { curValue = getClass( elem ); - cur = elem.nodeType === 1 && - ( " " + curValue + " " ).replace( rclass, " " ); + cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " ); if ( cur ) { j = 0; @@ -41,7 +39,7 @@ jQuery.fn.extend( { } // Only assign if different to avoid unneeded rendering. - finalValue = jQuery.trim( cur ); + finalValue = stripAndCollapse( cur ); if ( curValue !== finalValue ) { elem.setAttribute( "class", finalValue ); } @@ -67,14 +65,13 @@ jQuery.fn.extend( { } if ( typeof value === "string" && value ) { - classes = value.match( rnotwhite ) || []; + classes = value.match( rnothtmlwhite ) || []; while ( ( elem = this[ i++ ] ) ) { curValue = getClass( elem ); // This expression is here for better compressibility (see addClass) - cur = elem.nodeType === 1 && - ( " " + curValue + " " ).replace( rclass, " " ); + cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " ); if ( cur ) { j = 0; @@ -87,7 +84,7 @@ jQuery.fn.extend( { } // Only assign if different to avoid unneeded rendering. - finalValue = jQuery.trim( cur ); + finalValue = stripAndCollapse( cur ); if ( curValue !== finalValue ) { elem.setAttribute( "class", finalValue ); } @@ -122,7 +119,7 @@ jQuery.fn.extend( { // Toggle individual class names i = 0; self = jQuery( this ); - classNames = value.match( rnotwhite ) || []; + classNames = value.match( rnothtmlwhite ) || []; while ( ( className = classNames[ i++ ] ) ) { @@ -165,10 +162,8 @@ jQuery.fn.extend( { className = " " + selector + " "; while ( ( elem = this[ i++ ] ) ) { if ( elem.nodeType === 1 && - ( " " + getClass( elem ) + " " ).replace( rclass, " " ) - .indexOf( className ) > -1 - ) { - return true; + ( " " + stripAndCollapse( getClass( elem ) ) + " " ).indexOf( className ) > -1 ) { + return true; } } diff --git a/src/attributes/val.js b/src/attributes/val.js index e23aa9a21..fbf406929 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -1,13 +1,13 @@ define( [ "../core", + "../core/stripAndCollapse", "./support", "../core/init" -], function( jQuery, support ) { +], function( jQuery, stripAndCollapse, support ) { "use strict"; -var rreturn = /\r/g, - rspaces = /[\x20\t\r\n\f]+/g; +var rreturn = /\r/g; jQuery.fn.extend( { val: function( value ) { @@ -91,7 +91,7 @@ jQuery.extend( { // option.text throws exceptions (#14686, #14858) // Strip and collapse whitespace // https://html.spec.whatwg.org/#strip-and-collapse-whitespace - jQuery.trim( jQuery.text( elem ) ).replace( rspaces, " " ); + stripAndCollapse( jQuery.text( elem ) ); } }, select: { |