🌐 AI搜索 & 代理 主页
Skip to content

Commit df326d9

Browse files
committed
CSS: Don’t trim whitespace of undefined custom property
Fixes gh-5105 Signed-off-by: Anders Kaseorg <andersk@mit.edu>
1 parent d2436df commit df326d9

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/css/curCSS.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function curCSS( elem, name, computed ) {
1515
ret = computed.getPropertyValue( name ) || computed[ name ];
1616

1717
// trim whitespace for custom property (issue gh-4926)
18-
if ( isCustomProp ) {
18+
if ( isCustomProp && ret !== undefined ) {
1919

2020
// rtrim treats U+000D CARRIAGE RETURN and U+000C FORM FEED
2121
// as whitespace while CSS does not, but this is not a problem

test/unit/css.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {
17561756
$elem = jQuery( "<div>" ).addClass( "test__customProperties" )
17571757
.appendTo( "#qunit-fixture" ),
17581758
webkitOrBlink = /\bsafari\b/i.test( navigator.userAgent ),
1759-
expected = 17;
1759+
expected = 18;
17601760

17611761
if ( webkitOrBlink ) {
17621762
expected -= 2;
@@ -1802,6 +1802,7 @@ QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {
18021802
assert.equal( $elem.css( "--prop10" ), "val10", "Multiple preceding and following escaped unicode whitespace trimmed" );
18031803
assert.equal( $elem.css( "--prop11" ), "val11", "Multiple preceding and following unicode whitespace trimmed" );
18041804
assert.equal( $elem.css( "--prop12" ), "\u000Bval12\u000B", "Multiple preceding and following non-CSS whitespace reserved" );
1805+
assert.equal( $elem.css( "--nonexistent" ), undefined );
18051806
} );
18061807

18071808
// IE doesn't support CSS variables.

0 commit comments

Comments
 (0)