File tree 2 files changed +14
-0
lines changed
2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,12 @@ func createDefaultPolicy() *bluemonday.Policy {
85
85
// Allow icons, emojis, chroma syntax and keyword markup on span
86
86
policy .AllowAttrs ("class" ).Matching (regexp .MustCompile (`^((icon(\s+[\p{L}\p{N}_-]+)+)|(emoji))$|^([a-z][a-z0-9]{0,2})$|^` + keywordClass + `$` )).OnElements ("span" )
87
87
88
+ // Allow 'style' attribute on text elements.
89
+ policy .AllowAttrs ("style" ).OnElements ("span" , "p" )
90
+
91
+ // Allow 'color' property for the style attribute on text elements.
92
+ policy .AllowStyles ("color" ).OnElements ("span" , "p" )
93
+
88
94
// Allow generally safe attributes
89
95
generalSafeAttrs := []string {
90
96
"abbr" , "accept" , "accept-charset" ,
Original file line number Diff line number Diff line change @@ -45,6 +45,14 @@ func Test_Sanitizer(t *testing.T) {
45
45
`<input type="checkbox" disabled=""/>unchecked` , `<input type="checkbox" disabled=""/>unchecked` ,
46
46
`<span class="emoji dropdown">NAUGHTY</span>` , `<span>NAUGHTY</span>` ,
47
47
`<span class="emoji">contents</span>` , `<span class="emoji">contents</span>` ,
48
+
49
+ // Color property
50
+ `<span style="color: red">Hello World</span>` , `<span style="color: red">Hello World</span>` ,
51
+ `<p style="color: red">Hello World</p>` , `<p style="color: red">Hello World</p>` ,
52
+ `<code style="color: red">Hello World</code>` , `<code>Hello World</code>` ,
53
+ `<span style="bad-color: red">Hello World</span>` , `<span>Hello World</span>` ,
54
+ `<p style="bad-color: red">Hello World</p>` , `<p>Hello World</p>` ,
55
+ `<code style="bad-color: red">Hello World</code>` , `<code>Hello World</code>` ,
48
56
}
49
57
50
58
for i := 0 ; i < len (testCases ); i += 2 {
You can’t perform that action at this time.
0 commit comments