Skip to content
Permalink
Browse files

Attributes: Trim whitespace from option text when returned as a value

Fixes #14858
Ref #14686
Closes gh-1531
  • Loading branch information
johnhoven authored and dmethvin committed Mar 6, 2014
1 parent 5a1db91 commit 9ec429cf6270e455aba4eba85f4db80e633806b6
Showing with 17 additions and 1 deletion.
  1. +1 −0 AUTHORS.txt
  2. +3 −1 src/attributes/val.js
  3. +13 −0 test/unit/attributes.js
@@ -210,4 +210,5 @@ S. Andrew Sheppard <andrew@wq.io>
Roman Reiß <me@silverwind.io>
Benjy Cui <benjytrys@gmail.com>
Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>
John Hoven <hovenj@gmail.com>

@@ -74,7 +74,9 @@ jQuery.extend({
var val = jQuery.find.attr( elem, "value" );
return val != null ?
val :
jQuery.text( elem );
// Support: IE10-11+
// option.text throws exceptions (#14686, #14858)
jQuery.trim( jQuery.text( elem ) );
}
},
select: {
@@ -1462,3 +1462,16 @@ test( "should not throw at $(option).val() (#14686)", 1, function() {
ok( false );
}
});

test( "Insignificant white space returned for $(option).val() (#14858)", function() {
expect ( 3 );

var val = jQuery( "<option></option>" ).val();
equal( val.length, 0, "Empty option should have no value" );

val = jQuery( "<option> </option>" ).val();
equal( val.length, 0, "insignificant white-space returned for value" );

val = jQuery( "<option> test </option>" ).val();
equal( val.length, 4, "insignificant white-space returned for value" );
});

0 comments on commit 9ec429c

Please sign in to comment.
You can’t perform that action at this time.