瀏覽代碼

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

FelisCatus 10 年之前
父節點
當前提交
55fba179f0
共有 2 個文件被更改,包括 5 次插入1 次删除
  1. 1 1
      omega-pac/src/shexp_utils.coffee
  2. 4 0
      omega-pac/test/shexp_utils.coffee

+ 1 - 1
omega-pac/src/shexp_utils.coffee

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

+ 4 - 0
omega-pac/test/shexp_utils.coffee

@@ -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\\+$'