Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regular expression for quoted values in parentheses (+ add test) #400

Merged
merged 2 commits into from
Feb 12, 2025
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
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;
}