Skip to content

Commit

Permalink
feat: add support for special characters and UTF8 characters in selec…
Browse files Browse the repository at this point in the history
…tors
  • Loading branch information
fczbkk committed Sep 22, 2015
1 parent badf85b commit e6b272f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/css-selector-generator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class CssSelectorGenerator
sanitizeItem: (item) ->
escape item
.replace /\%/g, '\\'
# special characters *+-./
.replace /\*\+\-\.\//g, '\\$&'

validateId: (id) ->
# ID must exist
Expand Down
10 changes: 10 additions & 0 deletions test/src/css-selector-generator.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ describe 'CSS Selector Generator', ->
it 'should sanitize ID selector', ->
expect(x.sanitizeItem 'aaa:bbb').toEqual 'aaa\\3Abbb'

it 'should escape special characters in ID selector', ->
expect(x.sanitizeItem 'aaa*bbb').toEqual 'aaa\*bbb'
expect(x.sanitizeItem 'aaa+bbb').toEqual 'aaa\+bbb'
expect(x.sanitizeItem 'aaa-bbb').toEqual 'aaa\-bbb'
expect(x.sanitizeItem 'aaa.bbb').toEqual 'aaa\.bbb'
expect(x.sanitizeItem 'aaa/bbb').toEqual 'aaa\/bbb'

it 'should escape ID selector containing UTF8 characters', ->
expect(x.sanitizeItem 'aaa✓bbb').toEqual 'aaa\\u2713bbb'

it 'should ignore ID attribute begining with a number', ->
expect(x.validateId '111aaa').toBe false

Expand Down

0 comments on commit e6b272f

Please sign in to comment.