Skip to content

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

Open
JounQin wants to merge 3 commits into
webpack:mainfrom
JounQin:patch-1
Open

fix: the ASCII whitespaces are preserved so can not be escaped#1668
JounQin wants to merge 3 commits into
webpack:mainfrom
JounQin:patch-1

Conversation

@JounQin
Copy link
Copy Markdown
Member

@JounQin JounQin commented Jun 8, 2026

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

close #1626

Breaking Changes

N/A

Additional Info

related https://infra.spec.whatwg.org/#ascii-whitespace

cc @alexander-akait

Copilot AI review requested due to automatic review settings June 8, 2026 10:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds coverage and updates escaping behavior for CSS Modules local identifiers, particularly around reserved/whitespace characters, to address issue #1626.

Changes:

  • Added a regression test + fixtures for "modules" option issue #1626.
  • Changed escapeLocalIdent to escape reserved/whitespace characters using hex-style escape sequences (and updated snapshots accordingly).
  • Updated spellchecker config to ignore generated test outputs.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/modules-option.test.js Adds a new regression test for issue #1626 under the "modules" option suite.
test/fixtures/modules/issue-1626/source.js Adds a JS entry fixture that imports the CSS fixture for issue #1626.
test/fixtures/modules/issue-1626/source.css Adds a CSS selector fixture intended to cover escaping around spaces/special chars.
test/snapshots/modules-option.test.js.snap Updates snapshots to reflect the new escaping output and adds snapshots for issue #1626.
src/utils.js Changes escapeLocalIdent escaping strategy for reserved/whitespace characters.
.cspell.json Ignores test/outputs in spellchecking.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils.js
Comment on lines +262 to +265
const reversedChartMapper = {};

// eslint-disable-next-line no-control-regex
const filenameReservedRegex = /[<>:"/\\|?*]/g;
const filenameReservedRegex = /([<>:"/\\|?*\s])/g;
Comment thread src/utils.js
Comment on lines +275 to +289
.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;
})
Comment thread src/utils.js

// eslint-disable-next-line no-control-regex
const filenameReservedRegex = /[<>:"/\\|?*]/g;
const filenameReservedRegex = /([<>:"/\\|?*\s])/g;
Comment thread src/utils.js

return escaped;
})
.replace(reControlChars, "-")
Comment on lines +1 to +7
a-b {
color: red;
}

a\C20b /* i.e. with spaces */ {
color: red;
}
Comment thread src/utils.js
return path.sep === "\\" ? file.replace(/\\/g, "/") : file;
}

const reversedChartMapper = {};
Copilot AI review requested due to automatic review settings June 8, 2026 10:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Comment thread src/utils.js
Comment on lines +262 to +265
const reversedChartMapper = {};

// eslint-disable-next-line no-control-regex
const filenameReservedRegex = /[<>:"/\\|?*]/g;
const filenameReservedRegex = /([<>:"/\\|?*\s])/g;
Comment thread src/utils.js
Comment on lines +275 to +289
.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;
})
Comment on lines +5 to +6
a\C20b /* i.e. with spaces */ {
color: red;
Comment thread src/utils.js

// eslint-disable-next-line no-control-regex
const filenameReservedRegex = /[<>:"/\\|?*]/g;
const filenameReservedRegex = /([<>:"/\\|?*\s])/g;
Comment thread src/utils.js
return path.sep === "\\" ? file.replace(/\\/g, "/") : file;
}

const reversedChartMapper = {};
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.28%. Comparing base (488cdb1) to head (6244836).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1668      +/-   ##
==========================================
+ Coverage   96.25%   96.28%   +0.02%     
==========================================
  Files          10       10              
  Lines        1201     1210       +9     
  Branches      463      465       +2     
==========================================
+ Hits         1156     1165       +9     
  Misses         40       40              
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JounQin
Copy link
Copy Markdown
Member Author

JounQin commented Jun 8, 2026

cc @alexander-akait

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSS modules with path which contains spaces does not work as expected

2 participants