mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
fix iframe autoclosing
This commit is contained in:
parent
28f08ad42a
commit
37ed856d8b
@ -69,8 +69,12 @@ func Sanitize(baseURL, input string) string {
|
|||||||
buffer.WriteString("<" + tagName + ">")
|
buffer.WriteString("<" + tagName + ">")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tagName == "iframe" {
|
||||||
|
// autoclose iframes
|
||||||
|
buffer.WriteString("</iframe>")
|
||||||
if wrap {
|
if wrap {
|
||||||
buffer.WriteString("</iframe></div>")
|
buffer.WriteString("</div>")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tagStack = append(tagStack, tagName)
|
tagStack = append(tagStack, tagName)
|
||||||
}
|
}
|
||||||
@ -80,6 +84,7 @@ func Sanitize(baseURL, input string) string {
|
|||||||
}
|
}
|
||||||
case html.EndTagToken:
|
case html.EndTagToken:
|
||||||
tagName := token.Data
|
tagName := token.Data
|
||||||
|
// iframes are autoclosed. see above
|
||||||
if tagName == "iframe" {
|
if tagName == "iframe" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,16 @@ func TestInvalidNestedTag(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidIFrame(t *testing.T) {
|
||||||
|
input := `<iframe src="http://example.org/"></iframe>`
|
||||||
|
expected := `<iframe src="http://example.org/" sandbox="allow-scripts allow-same-origin allow-popups" loading="lazy"></iframe>`
|
||||||
|
output := Sanitize("http://example.org/", input)
|
||||||
|
|
||||||
|
if expected != output {
|
||||||
|
t.Errorf("Wrong output:\nwant: %s\nhave: %s", expected, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestInvalidIFrame(t *testing.T) {
|
func TestInvalidIFrame(t *testing.T) {
|
||||||
input := `<iframe src="http://example.org/"></iframe>`
|
input := `<iframe src="http://example.org/"></iframe>`
|
||||||
expected := ``
|
expected := ``
|
||||||
|
Loading…
x
Reference in New Issue
Block a user