Migrate UrlWildcard to HostWildcard if possible on upgrade.

This commit is contained in:
FelisCatus 2014-11-07 16:06:03 +08:00
parent e988fa7c1c
commit 144b213348
2 changed files with 23 additions and 8 deletions

View File

@ -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(

View File

@ -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