Skip to content

fix: the ASCII whitespaces are preserved so can not be escaped #1632

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"**/fonts/**",
"node_modules",
"coverage",
"*.log"
"*.log",
"test/outputs"
]
}
20 changes: 18 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,10 @@ function normalizePath(file) {
return path.sep === "\\" ? file.replace(/\\/g, "/") : file;
}

const reversedChartMapper = {};

// eslint-disable-next-line no-control-regex
const filenameReservedRegex = /[<>:"/\\|?*]/g;
const filenameReservedRegex = /([<>:"/\\|?*\s])/g;
// eslint-disable-next-line no-control-regex
const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;

Expand All @@ -270,7 +272,21 @@ function escapeLocalIdent(localident) {
localident
// For `[hash]` placeholder
.replace(/^((-?[0-9])|--)/, "_$1")
.replace(filenameReservedRegex, "-")
.replace(filenameReservedRegex, (_, $1) => {
// normalize Windows path `\` as unix `/` for constancy
Copy link
Contributor Author

@JounQin JounQin May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure how to distinguish path.sep vs css \\ here.

cc @alexander-akait

const char = $1 === "\\" ? "/" : $1;

if (reversedChartMapper[char]) {
return reversedChartMapper[char];
}

const hex = char.charCodeAt(0).toString(16).toUpperCase();
const escaped = `\\C${hex}`;

reversedChartMapper[char] = escaped;

return escaped;
})
.replace(reControlChars, "-")
.replace(/\./g, "-"),
);
Expand Down
Loading