From ff2819911da6cbbed5ee42c35d695240f06e65e3 Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski-Owczarek Date: Mon, 13 Jan 2020 19:25:01 +0100 Subject: 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 --- test/unit/attributes.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'test/unit') 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( "" ).appendTo( "#qunit-fixture" ), + spaces = { + "\\t": { + html: " ", + val: "\t" + }, + "\\n": { + html: " ", + val: "\n" + }, + "\\r": { + html: " ", + 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( "" ).appendTo( "#qunit-fixture" ); + assert.equal( radio.val(), "attr" + val, "Value ending with space character (" + key + ") returned (set via HTML)" ); + + radio = jQuery( "" ).appendTo( "#qunit-fixture" ); + assert.equal( radio.val(), "at" + val + "tr", "Value with space character (" + key + ") in the middle returned (set via HTML)" ); + + radio = jQuery( "" ).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 ); -- cgit v1.2.3