diff --git a/AUTHORS.txt b/AUTHORS.txt index 70a97e8c3..0856478f2 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -210,4 +210,5 @@ S. Andrew Sheppard Roman Reiß Benjy Cui Rodrigo Rosenfeld Rosas +John Hoven diff --git a/src/attributes/val.js b/src/attributes/val.js index b13641b28..4a3b0e5c1 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -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: { diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 32fd7b958..2ab583caa 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -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( "" ).val(); + equal( val.length, 0, "Empty option should have no value" ); + + val = jQuery( "" ).val(); + equal( val.length, 0, "insignificant white-space returned for value" ); + + val = jQuery( "" ).val(); + equal( val.length, 4, "insignificant white-space returned for value" ); +});