mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
Merge pull request #76 from mprobst/self-closing
feat: Write self-closing tags with a />
This commit is contained in:
commit
717a976f69
|
@ -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><!DOCTYPE test></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",
|
||||
|
|
|
@ -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())))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user