File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -879,6 +879,7 @@ func (p *Policy) addDefaultElementsWithoutAttrs() {
879879 p .setOfElementsAllowedWithoutAttrs ["optgroup" ] = struct {}{}
880880 p .setOfElementsAllowedWithoutAttrs ["option" ] = struct {}{}
881881 p .setOfElementsAllowedWithoutAttrs ["p" ] = struct {}{}
882+ p .setOfElementsAllowedWithoutAttrs ["picture" ] = struct {}{}
882883 p .setOfElementsAllowedWithoutAttrs ["pre" ] = struct {}{}
883884 p .setOfElementsAllowedWithoutAttrs ["q" ] = struct {}{}
884885 p .setOfElementsAllowedWithoutAttrs ["rp" ] = struct {}{}
Original file line number Diff line number Diff line change @@ -3931,3 +3931,37 @@ func TestRemovingEmptySelfClosingTag(t *testing.T) {
39313931 expected )
39323932 }
39333933}
3934+
3935+ func TestIssue161 (t * testing.T ) {
3936+ // https://github.com/microcosm-cc/bluemonday/issues/161
3937+ //
3938+ // ```
3939+ // p.AllowElementsMatching(regexp.MustCompile(`^custom-`))
3940+ // p.AllowNoAttrs().Matching(regexp.MustCompile(`^custom-`))
3941+ // ```
3942+ // This does not work as expected. This looks like a limitation, and the
3943+ // question is whether the matching has to be applied in a second location
3944+ // to overcome the limitation.
3945+ //
3946+ // However the issue is really that the `.Matching()` returns an attribute
3947+ // test that has to be bound to some elements, it isn't a global test.
3948+ //
3949+ // This should work:
3950+ // ```
3951+ // p.AllowNoAttrs().Matching(regexp.MustCompile(`^custom-`)).OnElementsMatching(regexp.MustCompile(`^custom-`))
3952+ // ```
3953+ p := UGCPolicy ()
3954+ p .AllowElements ("picture" , "source" )
3955+ p .AllowAttrs ("srcset" , "src" , "type" , "media" ).OnElements ("source" )
3956+
3957+ input := `<picture><source src="b.jpg" media="(prefers-color-scheme: dark)"></source><img src="a.jpg"></picture>`
3958+ out := p .Sanitize (input )
3959+ expected := input
3960+ if out != expected {
3961+ t .Errorf (
3962+ "test failed;\n input : %s\n output : %s\n expected: %s" ,
3963+ input ,
3964+ out ,
3965+ expected )
3966+ }
3967+ }
You can’t perform that action at this time.
0 commit comments