From b61e3284ccc761c7458144a3e097f480bfb5e0b4 Mon Sep 17 00:00:00 2001 From: JorianWoltjer <26067369+JorianWoltjer@users.noreply.github.com> Date: Sun, 5 Jan 2025 16:46:15 +0100 Subject: [PATCH] Fix regular expression for quoted values in parentheses (+ add test) --- src/parse/index.ts | 4 +++- test/cases/quoted/ast.json | 36 ++++++++++++++++++++++++++++++-- test/cases/quoted/compressed.css | 2 +- test/cases/quoted/input.css | 2 ++ test/cases/quoted/output.css | 2 ++ 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/parse/index.ts b/src/parse/index.ts index ee76a6d8..e03d00be 100644 --- a/src/parse/index.ts +++ b/src/parse/index.ts @@ -313,7 +313,9 @@ export const parse = ( } // val - const val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/); + const val = match( + /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|[^)])*?\)|[^};])+)/, + ); const ret = pos({ type: CssTypes.declaration, diff --git a/test/cases/quoted/ast.json b/test/cases/quoted/ast.json index 8b3d6001..66634ee0 100644 --- a/test/cases/quoted/ast.json +++ b/test/cases/quoted/ast.json @@ -23,6 +23,38 @@ }, "source": "input.css" } + }, + { + "type": "declaration", + "property": "background", + "value": "url('more stuff); here') 50% 50% no-repeat", + "position": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 57 + }, + "source": "input.css" + } + }, + { + "type": "declaration", + "property": "background", + "value": "url(https://example.com/a;b) 50% 50% no-repeat", + "position": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 4, + "column": 61 + }, + "source": "input.css" + } } ], "position": { @@ -31,7 +63,7 @@ "column": 1 }, "end": { - "line": 3, + "line": 5, "column": 2 }, "source": "input.css" @@ -39,4 +71,4 @@ } ] } -} +} \ No newline at end of file diff --git a/test/cases/quoted/compressed.css b/test/cases/quoted/compressed.css index dd590eaa..66218374 100644 --- a/test/cases/quoted/compressed.css +++ b/test/cases/quoted/compressed.css @@ -1 +1 @@ -body{background:url('some;stuff;here') 50% 50% no-repeat;} +body{background:url('some;stuff;here') 50% 50% no-repeat;background:url('more stuff); here') 50% 50% no-repeat;background:url(https://example.com/a;b) 50% 50% no-repeat;} diff --git a/test/cases/quoted/input.css b/test/cases/quoted/input.css index db593220..9795642a 100644 --- a/test/cases/quoted/input.css +++ b/test/cases/quoted/input.css @@ -1,3 +1,5 @@ body { background: url('some;stuff;here') 50% 50% no-repeat; + background: url('more stuff); here') 50% 50% no-repeat; + background: url(https://example.com/a;b) 50% 50% no-repeat; } diff --git a/test/cases/quoted/output.css b/test/cases/quoted/output.css index db593220..9795642a 100644 --- a/test/cases/quoted/output.css +++ b/test/cases/quoted/output.css @@ -1,3 +1,5 @@ body { background: url('some;stuff;here') 50% 50% no-repeat; + background: url('more stuff); here') 50% 50% no-repeat; + background: url(https://example.com/a;b) 50% 50% no-repeat; }