diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2016-03-15 18:15:02 -0400 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2016-03-17 12:32:52 -0400 |
commit | da015d9ca07bfd07bfcb44cddb7defd04169d627 (patch) | |
tree | 711703857304ef319cbe6abdee0712ca8887e374 /src/attributes/val.js | |
parent | 88b91af26e431a3b8a917ecc17fdd79a884225e2 (diff) | |
download | jquery-da015d9ca07bfd07bfcb44cddb7defd04169d627.tar.gz jquery-da015d9ca07bfd07bfcb44cddb7defd04169d627.zip |
Attributes: strip/collapse whitespace for set values on selects
Fixes gh-2978
Close gh-3002
Diffstat (limited to 'src/attributes/val.js')
-rw-r--r-- | src/attributes/val.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/attributes/val.js b/src/attributes/val.js index d4ed96f31..33b1dbea6 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -4,7 +4,8 @@ define( [ "../core/init" ], function( jQuery, support ) { -var rreturn = /\r/g; +var rreturn = /\r/g, + rspaces = /[\x20\t\r\n\f]+/g; jQuery.fn.extend( { val: function( value ) { @@ -84,7 +85,9 @@ jQuery.extend( { // Support: IE10-11+ // option.text throws exceptions (#14686, #14858) - jQuery.trim( jQuery.text( elem ) ); + // Strip and collapse whitespace + // https://html.spec.whatwg.org/#strip-and-collapse-whitespace + jQuery.trim( jQuery.text( elem ) ).replace( rspaces, " " ); } }, select: { @@ -138,7 +141,7 @@ jQuery.extend( { while ( i-- ) { option = options[ i ]; - if ( jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0 ) { + if ( jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 ) { // Support: IE6 // When new option element is added to select box we need to |