diff --git a/lib/resolve-value.js b/lib/resolve-value.js index 1138a68..6f27956 100644 --- a/lib/resolve-value.js +++ b/lib/resolve-value.js @@ -10,7 +10,7 @@ var cloneSpliceParentOntoNodeWhen = require('./clone-splice-parent-onto-node-whe // var() = var( [, ]? ) // 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*\)/); function toString(value) { return String(value); diff --git a/test/fixtures/whitespace-in-var-declaration.css b/test/fixtures/whitespace-in-var-declaration.css new file mode 100644 index 0000000..731004f --- /dev/null +++ b/test/fixtures/whitespace-in-var-declaration.css @@ -0,0 +1,9 @@ +:root { + --foo: 1px; +} + +.bar { + width: var( --foo ); + height: var( --foo); + margin-top: var(--foo ); +} \ No newline at end of file diff --git a/test/fixtures/whitespace-in-var-declaration.expected.css b/test/fixtures/whitespace-in-var-declaration.expected.css new file mode 100644 index 0000000..5ffaa7a --- /dev/null +++ b/test/fixtures/whitespace-in-var-declaration.expected.css @@ -0,0 +1,5 @@ +.bar { + width: 1px; + height: 1px; + margin-top: 1px; +} \ No newline at end of file diff --git a/test/test.js b/test/test.js index 30351c0..f0879f7 100644 --- a/test/test.js +++ b/test/test.js @@ -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',