Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/resolve-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var cloneSpliceParentOntoNodeWhen = require('./clone-splice-parent-onto-node-whe
// var() = var( <custom-property-name> [, <any-value> ]? )
// matches `name[, fallback]`, captures "name" and "fallback"
// See: http://dev.w3.org/csswg/css-variables/#funcdef-var
var RE_VAR_FUNC = (/var\((--[^,\s]+?)(?:\s*,\s*(.+))?\)/);
var RE_VAR_FUNC = (/var\(\s*(--[^,\s]+?)(?:\s*,\s*(.+))?\s*\)/);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benwest Let's add some tests


function toString(value) {
return String(value);
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/whitespace-in-var-declaration.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:root {
--foo: 1px;
}

.bar {
width: var( --foo );
height: var( --foo);
margin-top: var(--foo );
}
5 changes: 5 additions & 0 deletions test/fixtures/whitespace-in-var-declaration.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.bar {
width: 1px;
height: 1px;
margin-top: 1px;
}
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ describe('postcss-css-variables', function() {
test('should not mangle outer function parentheses', 'nested-inside-other-func');
});

test('should accept whitespace in var() declarations', 'whitespace-in-var-declaration' )

it('should not parse malformed var() declarations', function() {
return expect(testPlugin(
'./test/fixtures/malformed-variable-usage.css',
Expand Down