Escape back slashes in shExp2RegExp. Add unit tests. Fix #473.

This commit is contained in:
FelisCatus 2015-05-22 21:54:42 +08:00
parent a80489c95c
commit 55fba179f0
2 changed files with 5 additions and 1 deletions

View File

@ -1,6 +1,6 @@
module.exports = exports =
regExpMetaChars: do ->
chars = '''[\^$.|?*+(){}/'''
chars = '''\\[\^$.|?*+(){}/'''
set = {}
for i in [0...chars.length]
set[chars.charCodeAt(i)] = true

View File

@ -13,3 +13,7 @@ describe 'ShexpUtils', ->
it 'should know the difference between escaped and unescaped slashes', ->
regex = ShexpUtils.escapeSlash '\\\\/\\/test\\/'
regex.should.equal '\\\\\\/\\/test\\/'
describe '#shExp2RegExp', ->
it 'should escape regex meta chars and back slashes', ->
regex = ShexpUtils.shExp2RegExp 'this.is|a\\test+'
regex.should.equal '^this\\.is\\|a\\\\test\\+$'