From 5113b16e4bfccea3493d477cb939b27b6078e8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski-Owczarek?= Date: Mon, 18 May 2020 17:40:41 +0200 Subject: [PATCH] CSS: Don't break `.css( array )` jQuery 1.9 added support for array input to the `.css()` method; so far Migrate was crashing with such input. Fixes gh-357 --- src/jquery/css.js | 2 +- test/css.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/jquery/css.js b/src/jquery/css.js index 74c82547..f0200c56 100644 --- a/src/jquery/css.js +++ b/src/jquery/css.js @@ -101,7 +101,7 @@ oldFnCss = jQuery.fn.css; jQuery.fn.css = function( name, value ) { var camelName, origThis = this; - if ( typeof name !== "string" ) { + if ( name && typeof name === "object" && !Array.isArray( name ) ) { jQuery.each( name, function( n, v ) { jQuery.fn.css.call( origThis, n, v ); } ); diff --git a/test/css.js b/test/css.js index 05df35e8..4891fad2 100644 --- a/test/css.js +++ b/test/css.js @@ -44,6 +44,22 @@ QUnit[ ( jQueryVersionSince( "3.4.0" ) && typeof Proxy !== "undefined" ) ? "test delete jQuery.cssProps.devoHat; } ); +QUnit.test( "jQuery.css with arrays", function( assert ) { + assert.expect( 2 ); + + expectNoWarning( assert, "String value direct", function() { + var cssValues = jQuery( "
" ) + .css( { + lineHeight: "1", + fontSize: "16px" + } ) + .css( [ "font-size", "lineHeight" ] ); + + assert.deepEqual( cssValues, { "font-size": "16px", lineHeight: "1" }, + ".css( array ) works" ); + } ); +} ); + QUnit.test( "jQuery.css with numbers", function( assert ) { var jQuery3OrOlder = compareVersions( jQuery.fn.jquery, "4.0.0" ) < 0, whitelist = [