mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-01-22 15:08:12 -05:00
Migrate UrlWildcard to HostWildcard if possible on upgrade.
This commit is contained in:
parent
e988fa7c1c
commit
144b213348
@ -12,6 +12,14 @@ module.exports = exports =
|
|||||||
url: Url.format(url)
|
url: Url.format(url)
|
||||||
host: url.hostname
|
host: url.hostname
|
||||||
scheme: url.protocol.replace(':', '')
|
scheme: url.protocol.replace(':', '')
|
||||||
|
|
||||||
|
urlWildcard2HostWildcard: (pattern) ->
|
||||||
|
result = pattern.match ///
|
||||||
|
^\*:\/\/ # Begins with *://
|
||||||
|
((?:\w|[?*.])+) # The host part follows.
|
||||||
|
\/\*$ # And ends with /*
|
||||||
|
///
|
||||||
|
result?[1]
|
||||||
tag: (condition) -> exports._condCache.tag(condition)
|
tag: (condition) -> exports._condCache.tag(condition)
|
||||||
analyze: (condition) -> exports._condCache.get condition, -> {
|
analyze: (condition) -> exports._condCache.get condition, -> {
|
||||||
analyzed: exports._handler(condition.conditionType).analyze.call(
|
analyzed: exports._handler(condition.conditionType).analyze.call(
|
||||||
|
@ -136,15 +136,22 @@ module.exports = (oldOptions, i18n) ->
|
|||||||
|
|
||||||
rules = try JSON.parse(oldOptions['rules'])
|
rules = try JSON.parse(oldOptions['rules'])
|
||||||
if rules
|
if rules
|
||||||
|
conditionFromRule = (rule) ->
|
||||||
|
switch rule['patternType']
|
||||||
|
when 'wildcard'
|
||||||
|
pattern = rule['urlPattern']
|
||||||
|
host = OmegaPac.Conditions.urlWildcard2HostWildcard(pattern)
|
||||||
|
if host
|
||||||
|
conditionType: 'HostWildcardCondition'
|
||||||
|
pattern: host
|
||||||
|
else
|
||||||
|
conditionType: 'UrlWildcardCondition'
|
||||||
|
pattern: pattern
|
||||||
|
else
|
||||||
|
conditionType: 'UrlRegexCondition'
|
||||||
|
pattern: rule['urlPattern']
|
||||||
auto.rules = for own _, rule of rules
|
auto.rules = for own _, rule of rules
|
||||||
profileName: nameMap[rule['profileId']] || 'direct'
|
profileName: nameMap[rule['profileId']] || 'direct'
|
||||||
condition:
|
condition: conditionFromRule(rule)
|
||||||
conditionType:
|
|
||||||
if rule['patternType'] == 'wildcard'
|
|
||||||
# TODO(catus): Recognize HostWildcardCondition.
|
|
||||||
'UrlWildcardCondition'
|
|
||||||
else
|
|
||||||
'UrlRegexCondition'
|
|
||||||
pattern: rule['urlPattern']
|
|
||||||
return options
|
return options
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user