Merge pull request #76 from mprobst/self-closing

feat: Write self-closing tags with a />
pull/77/head
Vytautas Šaltenis 2014-05-03 15:11:53 +03:00
commit 717a976f69
2 changed files with 21 additions and 5 deletions

View File

@ -200,16 +200,13 @@ func TestRawHtmlTag(t *testing.T) {
// Additonal token types: SelfClosing, Comment, DocType.
"<br/>",
"<p><br></p>\n",
"<p><br/></p>\n",
"<!-- Comment -->",
"<!-- Comment -->\n",
"<!DOCTYPE test>",
"<p>&lt;!DOCTYPE test&gt;</p>\n",
"<hr>",
"<hr>\n",
}
doTestsInlineParam(t, tests, 0, HTML_SKIP_STYLE|HTML_SANITIZE_OUTPUT)
}
@ -237,6 +234,21 @@ func TestQuoteEscaping(t *testing.T) {
doTestsInlineParam(t, tests, 0, HTML_SKIP_STYLE|HTML_SANITIZE_OUTPUT)
}
func TestSanitizeSelfClosingTag(t *testing.T) {
tests := []string{
"<hr>\n",
"<hr>\n",
"<hr/>\n",
"<hr/>\n",
// Make sure that evil attributes are stripped for self closing tags.
"<hr onclick=\"evil()\"/>\n",
"<hr/>\n",
}
doTestsInlineParam(t, tests, 0, HTML_SKIP_STYLE|HTML_SANITIZE_OUTPUT)
}
func TestEmphasis(t *testing.T) {
var tests = []string{
"nothing inline\n",

View File

@ -103,7 +103,11 @@ func sanitizeHtmlSafe(input []byte) []byte {
wr.WriteByte('"')
}
}
wr.WriteString(">")
if t == html.SelfClosingTagToken {
wr.WriteString("/>")
} else {
wr.WriteString(">")
}
} else {
wr.WriteString(html.EscapeString(string(tokenizer.Raw())))
}