Skip to content

Commit aa1a92a

Browse files
committed
fix(css): restrict @value from separator to CSS whitespace
JS \s also matches U+00A0 and other spaces that are valid inside an import name, which could select a from inside the name; limit both separator boundaries to the CSS whitespace set (space, tab, LF, FF, CR). Signed-off-by: Eshiv Pandey <[email protected]>
1 parent c7bff83 commit aa1a92a

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎lib/css/CssParser.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,12 @@ const scanRuleBody = (declarations, childRules) => {
564564
const parseValueAtRuleParams = (str) => {
565565
if (VALUE_IMPORT_FORM.test(str)) {
566566
str = str.replace(CSS_COMMENT, " ").trim().replace(/;$/, "");
567-
// `from` is a keyword: split on the first whitespace-delimited `from`, so a
568-
// path or import name containing the substring (e.g. `./from-colors.css`)
569-
// isn't mistaken for the separator.
570-
const fromMatch = /^([\s\S]+?)\s+from\s+([\s\S]+)$/i.exec(str);
567+
// Split on the first `from` keyword delimited by CSS whitespace (only
568+
// ` \t\n\f\r`, not JS `\s`, which also matches U+00A0 valid in a name),
569+
// so a path or name containing the substring (`./from-colors.css`) isn't it.
570+
const fromMatch = /^([\s\S]+?)[ \t\n\f\r]+from[ \t\n\f\r]+([\s\S]+)$/i.exec(
571+
str
572+
);
571573
const path = (fromMatch ? fromMatch[2] : "").trim().replace(/['"]/g, "");
572574
let content = (fromMatch ? fromMatch[1] : str).trim();
573575

0 commit comments

Comments
 (0)