mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-01-22 15:08:12 -05:00
Fix anaylze for HostWildcardCondition involving trimAsterisk. Fix #158.
This commit is contained in:
parent
f8fd10fca8
commit
590c3baed9
@ -218,8 +218,8 @@ module.exports = exports =
|
|||||||
if pattern.indexOf('**.') == 0
|
if pattern.indexOf('**.') == 0
|
||||||
shExp2RegExp pattern.substring(1), trimAsterisk: true
|
shExp2RegExp pattern.substring(1), trimAsterisk: true
|
||||||
else if pattern.indexOf('*.') == 0
|
else if pattern.indexOf('*.') == 0
|
||||||
shExp2RegExp(pattern.substring(2), trimAsterisk: true)
|
shExp2RegExp(pattern.substring(2), trimAsterisk: false)
|
||||||
.replace(/./, '(?:^|\\.)')
|
.replace(/./, '(?:^|\\.)').replace(/\.\*\$$/, '')
|
||||||
else
|
else
|
||||||
shExp2RegExp pattern, trimAsterisk: true
|
shExp2RegExp pattern, trimAsterisk: true
|
||||||
@safeRegex parts.join('|')
|
@safeRegex parts.join('|')
|
||||||
|
@ -113,6 +113,15 @@ describe 'Conditions', ->
|
|||||||
it 'should also match hostname without the optional level', ->
|
it 'should also match hostname without the optional level', ->
|
||||||
# https://github.com/FelisCatus/SwitchyOmega/wiki/Host-wildcard-condition
|
# https://github.com/FelisCatus/SwitchyOmega/wiki/Host-wildcard-condition
|
||||||
testCond(cond, 'http://example.com/', 'match')
|
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', ->
|
it 'should allow override of the magical behavior', ->
|
||||||
con =
|
con =
|
||||||
conditionType: 'HostWildcardCondition'
|
conditionType: 'HostWildcardCondition'
|
||||||
|
@ -131,16 +131,16 @@ describe 'RuleList', ->
|
|||||||
result.should.have.length(0)
|
result.should.have.length(0)
|
||||||
it 'should parse wildcard rules', ->
|
it 'should parse wildcard rules', ->
|
||||||
list = compose 'Wildcard': [
|
list = compose 'Wildcard': [
|
||||||
'*://example.com/*'
|
'*://example.com/abc/*'
|
||||||
]
|
]
|
||||||
result = parse(list, 'match', 'notmatch')
|
result = parse(list, 'match', 'notmatch')
|
||||||
result.should.have.length(1)
|
result.should.have.length(1)
|
||||||
result[0].should.eql(
|
result[0].should.eql(
|
||||||
source: '*://example.com/*'
|
source: '*://example.com/abc/*'
|
||||||
profileName: 'match'
|
profileName: 'match'
|
||||||
condition:
|
condition:
|
||||||
conditionType: 'UrlWildcardCondition'
|
conditionType: 'UrlWildcardCondition'
|
||||||
pattern: '*://example.com/*'
|
pattern: '*://example.com/abc/*'
|
||||||
)
|
)
|
||||||
it 'should parse RegExp rules', ->
|
it 'should parse RegExp rules', ->
|
||||||
list = compose 'RegExp': [
|
list = compose 'RegExp': [
|
||||||
|
Loading…
Reference in New Issue
Block a user