Open
Description
Bug report
Actual Behavior
generated src_render_js.js
:

source render.js
:
import * as styles from './space folder/render.module.css';
export function render() {
const el = document.createElement('div');
el.className = styles.text; // styles.text contains a space which breaks styling
document.getElementsByTagName('body')[0].appendChild(el);
el.innerHTML = 'hello, world';
}
Expected Behavior
The generated class
is src-space folder-render-module__text-WVNeAh
which contains a space, but it's not possible to escape spaces, so the spaces in path should be changed to __
for example.
How Do We Reproduce?
https://github.com/JounQin/rspack-css-modules-spaces
Run pnpm dev:webpack
Please paste the results of npx webpack-cli info
here, and mention other relevant information
Metadata
Metadata
Assignees
Labels
No labels
Activity
JounQin commentedon Dec 26, 2024
I tried to add space pattern into
css-loader/src/utils.js
Line 263 in 9dd1966
JounQin commentedon Dec 26, 2024
Not sure if #997 related.
JounQin commentedon Jan 13, 2025
@alexander-akait Any time to take a look?
alexander-akait commentedon Feb 4, 2025
Yeah, technically we have CSS.escape to escape special character before inserting them in JS and it works good for non space characters, but there are some limitation with the
class
attributeBut https://html.spec.whatwg.org/multipage/dom.html#global-attributes:classes-2
Let's fix it
JounQin commentedon Apr 15, 2025
@alexander-akait I don't know how to add a test case for it easily, or we just change the
filenameReservedRegex
?alexander-akait commentedon Apr 16, 2025
@JounQin I think we can change
filenameReservedRegex
and look at our tests, if we don't broken anything we can merge and do a patch releaseJounQin commentedon Apr 16, 2025
@alexander-akait Here we go #1632