Skip to content

Commit

Permalink
Merge pull request #151 from Gusted/self-closing-tag-bug
Browse files Browse the repository at this point in the history
Don't write self-closing tag with empty attributes
  • Loading branch information
buro9 committed Oct 3, 2022
2 parents 705c34a + cc9997e commit 07c5693
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ func (p *Policy) sanitize(r io.Reader, w io.Writer) error {
if _, err := buff.WriteString(" "); err != nil {
return err
}
break
}
break
}
if !skipElementContent {
if _, err := buff.WriteString(token.String()); err != nil {
Expand Down
18 changes: 18 additions & 0 deletions sanitize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3913,3 +3913,21 @@ func TestIssue147(t *testing.T) {
expected)
}
}

func TestRemovingEmptySelfClosingTag(t *testing.T) {
p := NewPolicy()

// Only broke when attribute policy was specified.
p.AllowAttrs("type").OnElements("input")

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

0 comments on commit 07c5693

Please sign in to comment.