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)
|
||||
host: url.hostname
|
||||
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)
|
||||
analyze: (condition) -> exports._condCache.get condition, -> {
|
||||
analyzed: exports._handler(condition.conditionType).analyze.call(
|
||||
|
@ -136,15 +136,22 @@ module.exports = (oldOptions, i18n) ->
|
||||
|
||||
rules = try JSON.parse(oldOptions['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
|
||||
profileName: nameMap[rule['profileId']] || 'direct'
|
||||
condition:
|
||||
conditionType:
|
||||
if rule['patternType'] == 'wildcard'
|
||||
# TODO(catus): Recognize HostWildcardCondition.
|
||||
'UrlWildcardCondition'
|
||||
else
|
||||
'UrlRegexCondition'
|
||||
pattern: rule['urlPattern']
|
||||
condition: conditionFromRule(rule)
|
||||
return options
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user