Skip to content

Commit

Permalink
Closes #147 by adding an example test
Browse files Browse the repository at this point in the history
  • Loading branch information
buro9 committed Jul 1, 2022
1 parent ba34525 commit 4f006b3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions sanitize_test.go
Expand Up @@ -3733,3 +3733,36 @@ func TestIssue146(t *testing.T) {
expected)
}
}

func TestIssue147(t *testing.T) {
// https://github.com/microcosm-cc/bluemonday/issues/147
//
// ```
// p.AllowElementsMatching(regexp.MustCompile(`^custom-`))
// p.AllowNoAttrs().Matching(regexp.MustCompile(`^custom-`))
// ```
// This does not work as expected. This looks like a limitation, and the
// question is whether the matching has to be applied in a second location
// to overcome the limitation.
//
// However the issue is really that the `.Matching()` returns an attribute
// test that has to be bound to some elements, it isn't a global test.
//
// This should work:
// ```
// p.AllowNoAttrs().Matching(regexp.MustCompile(`^custom-`)).OnElementsMatching(regexp.MustCompile(`^custom-`))
// ```
p := NewPolicy()
p.AllowNoAttrs().Matching(regexp.MustCompile(`^custom-`)).OnElementsMatching(regexp.MustCompile(`^custom-`))

input := `<custom-component>example</custom-component>`
out := p.Sanitize(input)
expected := `<custom-component>example</custom-component>`
if out != expected {
t.Errorf(
"test failed;\ninput : %s\noutput : %s\nexpected: %s",
input,
out,
expected)
}
}

0 comments on commit 4f006b3

Please sign in to comment.