Switch to more robust existing CSS escaping library

This commit is contained in:
Adam Wathan 2018-06-04 08:50:00 -04:00
parent c678d91fe0
commit 1de2a24eb3
4 changed files with 13 additions and 1 deletions

View file

@ -0,0 +1,5 @@
import escapeClassName from '../src/util/escapeClassName'
test('invalid characters are escaped', () => {
expect(escapeClassName('w:_$-1/2')).toEqual('w\\:_\\$-1\\/2')
})

View file

@ -43,6 +43,7 @@
},
"dependencies": {
"commander": "^2.11.0",
"css.escape": "^1.5.1",
"fs-extra": "^4.0.2",
"lodash": "^4.17.5",
"perfectionist": "^2.4.0",

View file

@ -1,3 +1,5 @@
import escape from 'css.escape'
export default function escapeClassName(className) {
return className.replace(/([^A-Za-z0-9\-])/g, '\\$1')
return escape(className)
}

View file

@ -1246,6 +1246,10 @@ cross-spawn@^5.0.1, cross-spawn@^5.1.0:
shebang-command "^1.2.0"
which "^1.2.9"
css.escape@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/css.escape/-/css.escape-1.5.1.tgz#42e27d4fa04ae32f931a4b4d4191fa9cddee97cb"
cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0":
version "0.3.2"
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.2.tgz#b8036170c79f07a90ff2f16e22284027a243848b"