Skip to content

Commit

Permalink
Switch to more robust existing CSS escaping library
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Jun 4, 2018
1 parent c678d91 commit 1de2a24
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions __tests__/escapeClassName.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import escapeClassName from '../src/util/escapeClassName'

test('invalid characters are escaped', () => {
expect(escapeClassName('w:_$-1/2')).toEqual('w\\:_\\$-1\\/2')
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/util/escapeClassName.js
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[email protected], "cssom@>= 0.3.2 < 0.4.0":
version "0.3.2"
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.2.tgz#b8036170c79f07a90ff2f16e22284027a243848b"
Expand Down

0 comments on commit 1de2a24

Please sign in to comment.