Skip to content
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
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