diff --git a/omega-pac/src/conditions.coffee b/omega-pac/src/conditions.coffee index 88766e0..bea7616 100644 --- a/omega-pac/src/conditions.coffee +++ b/omega-pac/src/conditions.coffee @@ -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( diff --git a/omega-target-chromium-extension/src/upgrade.coffee b/omega-target-chromium-extension/src/upgrade.coffee index 4fccb63..2f3c35a 100644 --- a/omega-target-chromium-extension/src/upgrade.coffee +++ b/omega-target-chromium-extension/src/upgrade.coffee @@ -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