Merge pull request #76 from mprobst/self-closing feat: Write self-closing tags with a />
Vytautas Ĺ altenis vytas@rtfb.lt
Sat, 03 May 2014 15:11:53 +0300
2 files changed,
21 insertions(+),
5 deletions(-)
M
inline_test.go
→
inline_test.go
@@ -200,16 +200,13 @@ "<p><iframe src=<a href=\"http://ha.ckers.org/scriptlet.html\">http://ha.ckers.org/scriptlet.html</a> <</p>\n",
// 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) }@@ -233,6 +230,21 @@
// Same test for an unknown element that does not switch into raw mode. `Here are <eviltag> some "quotes".`, "<p>Here are <eviltag> some "quotes".</p>\n", + } + 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) }
M
sanitize.go
→
sanitize.go
@@ -103,7 +103,11 @@ wr.WriteString(html.EscapeString(string(val)))
wr.WriteByte('"') } } - wr.WriteString(">") + if t == html.SelfClosingTagToken { + wr.WriteString("/>") + } else { + wr.WriteString(">") + } } else { wr.WriteString(html.EscapeString(string(tokenizer.Raw()))) }