From 590c3baed9fa7570ff823c2b1b896178d542b866 Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Sun, 4 Jan 2015 14:27:05 +0800 Subject: [PATCH] Fix anaylze for HostWildcardCondition involving trimAsterisk. Fix #158. --- omega-pac/src/conditions.coffee | 4 ++-- omega-pac/test/conditions.coffee | 9 +++++++++ omega-pac/test/rule_list.coffee | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/omega-pac/src/conditions.coffee b/omega-pac/src/conditions.coffee index cd267dc..138d077 100644 --- a/omega-pac/src/conditions.coffee +++ b/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('|') diff --git a/omega-pac/test/conditions.coffee b/omega-pac/test/conditions.coffee index 230bd15..ce2cd15 100644 --- a/omega-pac/test/conditions.coffee +++ b/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' diff --git a/omega-pac/test/rule_list.coffee b/omega-pac/test/rule_list.coffee index 2b483da..22c6909 100644 --- a/omega-pac/test/rule_list.coffee +++ b/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': [