aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2020-01-13 19:25:01 +0100
committerGitHub <noreply@github.com>2020-01-13 19:25:01 +0100
commitff2819911da6cbbed5ee42c35d695240f06e65e3 (patch)
treebf47e765a9cbed3935126d96f53f35f6f32b1795 /test/unit
parenteb35be528fdea40faab4d89ac859d38dfd024271 (diff)
downloadjquery-ff2819911da6cbbed5ee42c35d695240f06e65e3.tar.gz
jquery-ff2819911da6cbbed5ee42c35d695240f06e65e3.zip
Attributes: Refactor val(): don't strip carriage return, isolate IE workarounds
Before this change, `val()` was stripping out carriage return characters from the returned value. No test has relied on that. The logic was different for option elements as its custom defined hook was omitting this stripping logic. This commit gets rid of the carriage return removal and isolates the IE-only select val getter to be skipped in other browsers. Closes gh-4585
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/attributes.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index 386aadaf3..d592314a0 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -1196,6 +1196,57 @@ QUnit.test( "select.val(space characters) (gh-2978)", function( assert ) {
} );
} );
+QUnit.test( "radio.val(space characters)", function( assert ) {
+ assert.expect( 42 );
+
+ var radio = jQuery( "<input type='radio'/>" ).appendTo( "#qunit-fixture" ),
+ spaces = {
+ "\\t": {
+ html: "&#09;",
+ val: "\t"
+ },
+ "\\n": {
+ html: "&#10;",
+ val: "\n"
+ },
+ "\\r": {
+ html: "&#13;",
+ val: "\r"
+ },
+ "\\f": "\f",
+ "space": " ",
+ "\\u00a0": "\u00a0",
+ "\\u1680": "\u1680"
+ };
+
+ jQuery.each( spaces, function( key, obj ) {
+ var val = obj.val || obj;
+
+ radio.val( "attr" + val );
+ assert.equal( radio.val(), "attr" + val, "Value ending with space character (" + key + ") returned (set via val())" );
+
+ radio.val( "at" + val + "tr" );
+ assert.equal( radio.val(), "at" + val + "tr", "Value with space character (" + key + ") in the middle returned (set via val())" );
+
+ radio.val( val + "attr" );
+ assert.equal( radio.val(), val + "attr", "Value starting with space character (" + key + ") returned (set via val())" );
+ } );
+
+ jQuery.each( spaces, function( key, obj ) {
+ var val = obj.val || obj,
+ htmlVal = obj.html || obj;
+
+ radio = jQuery( "<input type='radio' value='attr" + htmlVal + "'/>" ).appendTo( "#qunit-fixture" );
+ assert.equal( radio.val(), "attr" + val, "Value ending with space character (" + key + ") returned (set via HTML)" );
+
+ radio = jQuery( "<input type='radio' value='at" + htmlVal + "tr'/>" ).appendTo( "#qunit-fixture" );
+ assert.equal( radio.val(), "at" + val + "tr", "Value with space character (" + key + ") in the middle returned (set via HTML)" );
+
+ radio = jQuery( "<input type='radio' value='" + htmlVal + "attr'/>" ).appendTo( "#qunit-fixture" );
+ assert.equal( radio.val(), val + "attr", "Value starting with space character (" + key + ") returned (set via HTML)" );
+ } );
+} );
+
var testAddClass = function( valueObj, assert ) {
assert.expect( 9 );