Unverified Commit 937884b6 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Fix CSS Identifier Cleaning (#12239)

parent 04f3d94b
......@@ -43,11 +43,11 @@ export function getCssModuleLocalIdent(
/\.module_/,
'_'
)
// Replace any characters not in the below set to prevent invalid
// CSS characters
// Replace invalid symbols with underscores instead of escaping
// https://mathiasbynens.be/notes/css-escapes#identifiers-strings
.replace(/[^a-zA-Z0-9-_]/g, '_')
// CSS classes can also not start with a digit or a hyphen and then a
//digit https://www.w3.org/TR/CSS21/syndata.html#characters
.replace(/^(\d|_\d|__)/, '')
// "they cannot start with a digit, two hyphens, or a hyphen followed by a digit [sic]"
// https://www.w3.org/TR/CSS21/syndata.html#characters
.replace(/^(\d|--|-\d)/, '__$1')
)
}
import styles from './index.module.css'
import styles1 from './index.module.css'
import styles2 from './55css.module.css'
export default () => (
<div className={styles.home} id="my-div">
<div className={styles1.home + ' ' + styles2.home} id="my-div">
hello world
</div>
)
......@@ -524,11 +524,13 @@ describe('Catch-all Route CSS Module Usage', () => {
it('should apply styles correctly', async () => {
const browser = await webdriver(appPort, '/post-1')
const background = await browser
const bg = await browser
.elementByCss('#my-div')
.getComputedCss('background-color')
expect(bg).toMatch(/rgb(a|)\(255, 0, 0/)
expect(background).toMatch(/rgb(a|)\(255, 0, 0/)
const fg = await browser.elementByCss('#my-div').getComputedCss('color')
expect(fg).toMatch(/rgb(a|)\(0, 128, 0/)
})
it(`should've emitted a single CSS file`, async () => {
......@@ -541,7 +543,7 @@ describe('Catch-all Route CSS Module Usage', () => {
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')
expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot(
`"._post__home__38gR-{background:red}"`
`".___post__home__38gR-{background:red}.__55css_home__qxXcH{color:green}"`
)
})
})
......@@ -540,7 +540,7 @@ describe('Catch-all Route CSS Module Usage', () => {
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')
expect(cssContent.replace(/\/\*.*?\*\//g, '').trim()).toMatchInlineSnapshot(
`"._post__home__psZf9{background:red}"`
`".___post__home__psZf9{background:red}"`
)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment