From f396bea9fa58b9f52c7907a64aae3b5053dbafb9 Mon Sep 17 00:00:00 2001 From: benwest Date: Wed, 20 Feb 2019 11:28:54 +0100 Subject: [PATCH 1/2] Accept whitespace in var( --var ) expression --- lib/resolve-value.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From a39c982fd6fa0fd174b3b760f7bfa1384f4955d6 Mon Sep 17 00:00:00 2001 From: benwest Date: Thu, 21 Feb 2019 11:03:52 +0100 Subject: [PATCH 2/2] added test --- test/fixtures/whitespace-in-var-declaration.css | 9 +++++++++ test/fixtures/whitespace-in-var-declaration.expected.css | 5 +++++ test/test.js | 2 ++ 3 files changed, 16 insertions(+) create mode 100644 test/fixtures/whitespace-in-var-declaration.css create mode 100644 test/fixtures/whitespace-in-var-declaration.expected.css 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',