]> source.dussan.org Git - jquery.git/commitdiff
CSS: Don’t trim whitespace of undefined custom property
authorAnders Kaseorg <andersk@mit.edu>
Mon, 19 Sep 2022 21:08:12 +0000 (14:08 -0700)
committerGitHub <noreply@github.com>
Mon, 19 Sep 2022 21:08:12 +0000 (23:08 +0200)
Fixes gh-5105
Closes gh-5106

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
src/css/curCSS.js
test/unit/css.js

index 15d624bbb98cfc506a57da5c4db0b8cf17841cbc..25b4630a5d487cedf89383080c9f096d6c7b9aa7 100644 (file)
@@ -15,7 +15,7 @@ function curCSS( elem, name, computed ) {
                ret = computed.getPropertyValue( name ) || computed[ name ];
 
                // trim whitespace for custom property (issue gh-4926)
-               if ( isCustomProp ) {
+               if ( isCustomProp && ret !== undefined ) {
 
                        // rtrim treats U+000D CARRIAGE RETURN and U+000C FORM FEED
                        // as whitespace while CSS does not, but this is not a problem
index a3e44bb442ce3583b6b8e68eb9e719ee05929c2e..b692caac9e375180ac02ac1726be9236ef99d2b2 100644 (file)
@@ -1748,6 +1748,7 @@ QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {
                "        --prop10:\f\r\n\t val10 \f\r\n\t;\n" +
                "        --prop11:\u000C\u000D\u000A\u0009\u0020val11\u0020\u0009\u000A\u000D\u000C;\n" +
                "        --prop12:\u000Bval12\u000B;\n" +
+               "        --empty:;\n" +
                "    }\n" +
                "</style>"
        );
@@ -1756,7 +1757,7 @@ QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {
                $elem = jQuery( "<div>" ).addClass( "test__customProperties" )
                        .appendTo( "#qunit-fixture" ),
                webkitOrBlink = /\bsafari\b/i.test( navigator.userAgent ),
-               expected = 17;
+               expected = 19;
 
        if ( webkitOrBlink ) {
                expected -= 2;
@@ -1802,6 +1803,8 @@ QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {
        assert.equal( $elem.css( "--prop10" ), "val10", "Multiple preceding and following escaped unicode whitespace trimmed" );
        assert.equal( $elem.css( "--prop11" ), "val11", "Multiple preceding and following unicode whitespace trimmed" );
        assert.equal( $elem.css( "--prop12" ), "\u000Bval12\u000B", "Multiple preceding and following non-CSS whitespace reserved" );
+       assert.equal( $elem.css( "--empty" ), undefined );
+       assert.equal( $elem.css( "--nonexistent" ), undefined );
 } );
 
 // IE doesn't support CSS variables.