Do case-insensitive match on BEGIN/END for SwitchyRuleList. Fix #48.

And also, set the default section to WILDCARD for better compatibility.
This commit is contained in:
FelisCatus 2014-10-20 20:52:23 +08:00
parent 3badc664be
commit 2c8acfebbe
3 changed files with 9 additions and 7 deletions

View File

@ -57,17 +57,18 @@ module.exports = exports =
normal_rules = [] normal_rules = []
exclusive_rules = [] exclusive_rules = []
begin = false begin = false
section = 'WILDCARD'
for line in text.split(/\n|\r/) for line in text.split(/\n|\r/)
line = line.trim() line = line.trim()
continue if line.length == 0 || line[0] == ';' continue if line.length == 0 || line[0] == ';'
if not begin if not begin
if line == '#BEGIN' if line.toUpperCase() == '#BEGIN'
begin = true begin = true
continue continue
if line == '#END' if line.toUpperCase() == '#END'
break break
if line[0] == '[' and line[line.length - 1] == ']' if line[0] == '[' and line[line.length - 1] == ']'
section = line.substring(1, line.length - 1) section = line.substring(1, line.length - 1).toUpperCase()
continue continue
source = line source = line
profile = matchProfileName profile = matchProfileName
@ -77,10 +78,10 @@ module.exports = exports =
list = exclusive_rules list = exclusive_rules
line = line.substring(1) line = line.substring(1)
cond = switch section cond = switch section
when 'Wildcard' when 'WILDCARD'
conditionType: 'UrlWildcardCondition' conditionType: 'UrlWildcardCondition'
pattern: line pattern: line
when 'RegExp' when 'REGEXP'
conditionType: 'UrlRegexCondition' conditionType: 'UrlRegexCondition'
pattern: line pattern: line
else else

View File

@ -69,5 +69,6 @@ angular.module('omegaDecoration', []).value('profileIcons', {
ngModel.$render() ngModel.$render()
scope.getName = (profile) -> scope.getName = (profile) ->
scope.dispName?({$profile: profile}) || profile?.name if profile
scope.dispName?({$profile: profile}) || profile?.name
) )

View File

@ -8,7 +8,7 @@
.well .well
span.glyphicon(class='{{profileIcons[attached.profileType]}}') span.glyphicon(class='{{profileIcons[attached.profileType]}}')
= ' ' = ' '
| {{attached.sourceUrl || ('options_ruleListLineCount' | tr:[attached.ruleList.split('\r?\n').length])}} | {{attached.sourceUrl || ('options_ruleListLineCount' | tr:[attached.ruleList.split('\n').length])}}
.modal-footer .modal-footer
button.btn.btn-default(ng-click='$dismiss()') {{'dialog_cancel' | tr}} button.btn.btn-default(ng-click='$dismiss()') {{'dialog_cancel' | tr}}
button.btn.btn-danger(type='button' ng-click='$close("ok")') {{'options_deleteAttached' | tr}} button.btn.btn-danger(type='button' ng-click='$close("ok")') {{'options_deleteAttached' | tr}}