File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 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 {
8585 // Allow icons, emojis, chroma syntax and keyword markup on span
8686 policy .AllowAttrs ("class" ).Matching (regexp .MustCompile (`^((icon(\s+[\p{L}\p{N}_-]+)+)|(emoji))$|^([a-z][a-z0-9]{0,2})$|^` + keywordClass + `$` )).OnElements ("span" )
8787
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+
8894 // Allow generally safe attributes
8995 generalSafeAttrs := []string {
9096 "abbr" , "accept" , "accept-charset" ,
Original file line number Diff line number Diff line change @@ -45,6 +45,14 @@ func Test_Sanitizer(t *testing.T) {
4545 `<input type="checkbox" disabled=""/>unchecked` , `<input type="checkbox" disabled=""/>unchecked` ,
4646 `<span class="emoji dropdown">NAUGHTY</span>` , `<span>NAUGHTY</span>` ,
4747 `<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>` ,
4856 }
4957
5058 for i := 0 ; i < len (testCases ); i += 2 {
You can’t perform that action at this time.
0 commit comments