Skip to content

Commit

Permalink
Fix regular expression for quoted values in parentheses (+ add test)
Browse files Browse the repository at this point in the history
  • Loading branch information
JorianWoltjer committed Jan 5, 2025
1 parent d745281 commit b61e328
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ export const parse = (
}

// val
const val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/);
const val = match(
/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|[^)])*?\)|[^};])+)/,
);

const ret = pos<CssDeclarationAST>({
type: CssTypes.declaration,
Expand Down
36 changes: 34 additions & 2 deletions test/cases/quoted/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -31,12 +63,12 @@
"column": 1
},
"end": {
"line": 3,
"line": 5,
"column": 2
},
"source": "input.css"
}
}
]
}
}
}
2 changes: 1 addition & 1 deletion test/cases/quoted/compressed.css
Original file line number Diff line number Diff line change
@@ -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;}
2 changes: 2 additions & 0 deletions test/cases/quoted/input.css
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions test/cases/quoted/output.css
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit b61e328

Please sign in to comment.