Browse Source

Fix anaylze for HostWildcardCondition involving trimAsterisk. Fix #158.

FelisCatus 11 years ago
parent
commit
590c3baed9

+ 2 - 2
omega-pac/src/conditions.coffee

@@ -218,8 +218,8 @@ module.exports = exports =
           if pattern.indexOf('**.') == 0
             shExp2RegExp pattern.substring(1), trimAsterisk: true
           else if pattern.indexOf('*.') == 0
-            shExp2RegExp(pattern.substring(2), trimAsterisk: true)
-              .replace(/./, '(?:^|\\.)')
+            shExp2RegExp(pattern.substring(2), trimAsterisk: false)
+              .replace(/./, '(?:^|\\.)').replace(/\.\*\$$/, '')
           else
             shExp2RegExp pattern, trimAsterisk: true
         @safeRegex parts.join('|')

+ 9 - 0
omega-pac/test/conditions.coffee

@@ -113,6 +113,15 @@ describe 'Conditions', ->
     it 'should also match hostname without the optional level', ->
       # https://github.com/FelisCatus/SwitchyOmega/wiki/Host-wildcard-condition
       testCond(cond, 'http://example.com/', 'match')
+    it 'should process patterns like *.*example.com correctly', ->
+      # https://github.com/FelisCatus/SwitchyOmega/issues/158
+      con =
+        conditionType: 'HostWildcardCondition'
+        pattern: '*.*example.com'
+      testCond(con, 'http://example.com/', 'match')
+      testCond(con, 'http://www.example.com/', 'match')
+      testCond(con, 'http://www.some-example.com/', 'match')
+      testCond(con, 'http://xample.com/', not 'match')
     it 'should allow override of the magical behavior', ->
       con =
         conditionType: 'HostWildcardCondition'

+ 3 - 3
omega-pac/test/rule_list.coffee

@@ -131,16 +131,16 @@ describe 'RuleList', ->
       result.should.have.length(0)
     it 'should parse wildcard rules', ->
       list = compose 'Wildcard': [
-        '*://example.com/*'
+        '*://example.com/abc/*'
       ]
       result = parse(list, 'match', 'notmatch')
       result.should.have.length(1)
       result[0].should.eql(
-        source: '*://example.com/*'
+        source: '*://example.com/abc/*'
         profileName: 'match'
         condition:
           conditionType: 'UrlWildcardCondition'
-          pattern: '*://example.com/*'
+          pattern: '*://example.com/abc/*'
       )
     it 'should parse RegExp rules', ->
       list = compose 'RegExp': [