@@ -44,7 +44,7 @@ func newMarkup() {
44
44
continue
45
45
}
46
46
47
- if name == "sanitizer" {
47
+ if name == "sanitizer" || strings . HasPrefix ( name , "sanitizer." ) {
48
48
newMarkupSanitizer (name , sec )
49
49
} else {
50
50
newMarkupRenderer (name , sec )
@@ -67,44 +67,36 @@ func newMarkupSanitizer(name string, sec *ini.Section) {
67
67
return
68
68
}
69
69
70
- elements := sec .Key ("ELEMENT" ).ValueWithShadows ()
71
- allowAttrs := sec .Key ("ALLOW_ATTR" ).ValueWithShadows ()
72
- regexps := sec .Key ("REGEXP" ).ValueWithShadows ()
70
+ elements := sec .Key ("ELEMENT" ).Value ()
71
+ allowAttrs := sec .Key ("ALLOW_ATTR" ).Value ()
72
+ regexpStr := sec .Key ("REGEXP" ).Value ()
73
73
74
- if len (elements ) != len (allowAttrs ) ||
75
- len (elements ) != len (regexps ) {
76
- log .Error ("All three keys in markup.%s (ELEMENT, ALLOW_ATTR, REGEXP) must be defined the same number of times! Got %d, %d, and %d respectively." , name , len (elements ), len (allowAttrs ), len (regexps ))
74
+ if regexpStr == "" {
75
+ rule := MarkupSanitizerRule {
76
+ Element : elements ,
77
+ AllowAttr : allowAttrs ,
78
+ Regexp : nil ,
79
+ }
80
+
81
+ ExternalSanitizerRules = append (ExternalSanitizerRules , rule )
77
82
return
78
83
}
79
84
80
- ExternalSanitizerRules = make ([]MarkupSanitizerRule , 0 , len (elements ))
81
-
82
- for index , pattern := range regexps {
83
- if pattern == "" {
84
- rule := MarkupSanitizerRule {
85
- Element : elements [index ],
86
- AllowAttr : allowAttrs [index ],
87
- Regexp : nil ,
88
- }
89
- ExternalSanitizerRules = append (ExternalSanitizerRules , rule )
90
- continue
91
- }
92
-
93
- // Validate when parsing the config that this is a valid regular
94
- // expression. Then we can use regexp.MustCompile(...) later.
95
- compiled , err := regexp .Compile (pattern )
96
- if err != nil {
97
- log .Error ("In module.%s: REGEXP at definition %d failed to compile: %v" , name , index + 1 , err )
98
- continue
99
- }
85
+ // Validate when parsing the config that this is a valid regular
86
+ // expression. Then we can use regexp.MustCompile(...) later.
87
+ compiled , err := regexp .Compile (regexpStr )
88
+ if err != nil {
89
+ log .Error ("In module.%s: REGEXP (%s) at definition %d failed to compile: %v" , regexpStr , name , err )
90
+ return
91
+ }
100
92
101
- rule := MarkupSanitizerRule {
102
- Element : elements [index ],
103
- AllowAttr : allowAttrs [index ],
104
- Regexp : compiled ,
105
- }
106
- ExternalSanitizerRules = append (ExternalSanitizerRules , rule )
93
+ rule := MarkupSanitizerRule {
94
+ Element : elements ,
95
+ AllowAttr : allowAttrs ,
96
+ Regexp : compiled ,
107
97
}
98
+
99
+ ExternalSanitizerRules = append (ExternalSanitizerRules , rule )
108
100
}
109
101
110
102
func newMarkupRenderer (name string , sec * ini.Section ) {
0 commit comments