Skip to content

Commit e6b272f

Browse files
committed
feat: add support for special characters and UTF8 characters in selectors
1 parent badf85b commit e6b272f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/css-selector-generator.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class CssSelectorGenerator
3232
sanitizeItem: (item) ->
3333
escape item
3434
.replace /\%/g, '\\'
35+
# special characters *+-./
36+
.replace /\*\+\-\.\//g, '\\$&'
3537

3638
validateId: (id) ->
3739
# ID must exist

test/src/css-selector-generator.spec.coffee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ describe 'CSS Selector Generator', ->
111111
it 'should sanitize ID selector', ->
112112
expect(x.sanitizeItem 'aaa:bbb').toEqual 'aaa\\3Abbb'
113113

114+
it 'should escape special characters in ID selector', ->
115+
expect(x.sanitizeItem 'aaa*bbb').toEqual 'aaa\*bbb'
116+
expect(x.sanitizeItem 'aaa+bbb').toEqual 'aaa\+bbb'
117+
expect(x.sanitizeItem 'aaa-bbb').toEqual 'aaa\-bbb'
118+
expect(x.sanitizeItem 'aaa.bbb').toEqual 'aaa\.bbb'
119+
expect(x.sanitizeItem 'aaa/bbb').toEqual 'aaa\/bbb'
120+
121+
it 'should escape ID selector containing UTF8 characters', ->
122+
expect(x.sanitizeItem 'aaa✓bbb').toEqual 'aaa\\u2713bbb'
123+
114124
it 'should ignore ID attribute begining with a number', ->
115125
expect(x.validateId '111aaa').toBe false
116126

0 commit comments

Comments
 (0)