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 2 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"
]
}
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function normalizePath(file) {
}

// 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 Down
46 changes: 23 additions & 23 deletions test/__snapshots__/modules-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -392,56 +392,56 @@ ___CSS_LOADER_EXPORT___.push([module.id, \`/* class="😀" */
/* Local */

/* class="😀" */
.\\\\ {
.- {
color: red;
}

/* class="😀 😓" */
.\\\\ .\\\\ {
.-.- {
color: red;
}

/* class="😀" > class="😓" */
.\\\\ .\\\\ {
.- .- {
color: red;
}

.\\\\1F600 .a .\\\\1F600 {
color: red;
}

.\\\\ .\\\\ .\\\\ {
.- .- .- {
color: red;
}

div:not(.\\\\ ) {
div:not(.-) {
color: red;
}

.\\\\ .b {
.- .b {
color: red;
}

.b .\\\\ {
.b .- {
color: red;
}

.\\\\1F613 .\\\\ {
.\\\\1F613 .- {
color: red;
}

.\\\\1F613 .\\\\ {
.\\\\1F613 .- {
color: red;
}

.\\\\ > .\\\\ > .\\\\ {
.- > .- > .- {
color: red;
}
\`, ""]);
// Exports
export var a = \` \`;
export var b = \` \`;
export var c = \` \`;
export var a = \`-\`;
export var b = \`-\`;
export var c = \`-\`;
export default ___CSS_LOADER_EXPORT___;
"
`;
Expand Down Expand Up @@ -498,49 +498,49 @@ exports[`"modules" option issue #995 #2: result 1`] = `
/* Local */

/* class="😀" */
.\\ {
.- {
color: red;
}

/* class="😀 😓" */
.\\ .\\ {
.-.- {
color: red;
}

/* class="😀" > class="😓" */
.\\ .\\ {
.- .- {
color: red;
}

.\\1F600 .a .\\1F600 {
color: red;
}

.\\ .\\ .\\ {
.- .- .- {
color: red;
}

div:not(.\\ ) {
div:not(.-) {
color: red;
}

.\\ .b {
.- .b {
color: red;
}

.b .\\ {
.b .- {
color: red;
}

.\\1F613 .\\ {
.\\1F613 .- {
color: red;
}

.\\1F613 .\\ {
.\\1F613 .- {
color: red;
}

.\\ > .\\ > .\\ {
.- > .- > .- {
color: red;
}
",
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a test case

a-b { }
a\C20b { } /* i.e. with spaces */

The main problem we need to generate different CSS selectors for such case.

Even more - I think we should replace each control character on own unique symbol, we can generate it from code the character, so even special characters will always generate and unique selector. What do you think?

Copy link
Contributor Author

@JounQin JounQin Apr 21, 2025

Choose a reason for hiding this comment

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

Let's add a test case

OK, I'll add such case soon.

The main problem we need to generate different CSS selectors for such case.

Even more - I think we should replace each control character on own unique symbol, we can generate it from code the character, so even special characters will always generate and unique selector. What do you think?

That could work as expected, but is that common to have different white spaces in a single project? Is that a bit over engineering? But I'm also fine if you have strong opinion on this. What the symbol map would you prefer?

Copy link
Member

Choose a reason for hiding this comment

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

That could work as expected, but is that common to have different white spaces in a single project?

Usually no, but I think we can solve it more universal for any exotic cases, usually developers don't use such characters in path and in CSS selectors too 😄

I think we can just generate use number of a character... yeah it will create more longer CSS selectors, maybe we can use some compression algorithm here to get less length

Copy link
Contributor Author

Choose a reason for hiding this comment

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

usually developers don't use such characters in path and in CSS selectors too

I got this issue because we installed a common package in global mode. What means whenever css-loader is installed as global, it will be an issue for macOS at least with Application Support dir.

Copy link
Member

Choose a reason for hiding this comment

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

@JounQin got it, let's fix it

Expand Down