Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/net: html.Parse does not parse self closing token correctly #26566

Closed
npchp110 opened this issue Jul 24, 2018 · 2 comments
Closed

x/net: html.Parse does not parse self closing token correctly #26566

npchp110 opened this issue Jul 24, 2018 · 2 comments

Comments

@npchp110
Copy link

npchp110 commented Jul 24, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"

What did you do?

https://play.golang.org/p/fAXM0DtL6mW

package main

import (
	"os"
	"strings"

	"golang.org/x/net/html"
)

func main() {
	raw := `<video src="a.mp4"/><p>xx</p>`
	root, _ := html.Parse(strings.NewReader(raw))
	html.Render(os.Stdout, root)
}

What did you expect to see?

`<p>xx</p>' parsed as child of body:
<html><head></head><body><video src="a.mp4"></video><p>xx</p></body></html>

What did you see instead?

'<p>xx</p>' parsed as child of video:
<html><head></head><body><video src="a.mp4"><p>xx</p></video></body></html>
@gopherbot gopherbot added this to the Unreleased milestone Jul 24, 2018
@artyom
Copy link
Member

artyom commented Jul 24, 2018

I think parser behaves correctly here. Your input is non-conformant — spec tells that for video element "Neither tag is omissible" — so your input is parsed as if video element holds <p> which is what you see in rendering.

This program prints parsed tree nesting: https://play.golang.org/p/jHCa0PEpHGC

.html
..head
..body
...video
....p

Note that browsers also parse such input in a similar fashion — here's what tree produced Safari:

safari

@agnivade
Copy link
Contributor

agnivade commented Jul 8, 2019

/cc @nigeltao

@golang golang locked and limited conversation to collaborators Jul 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants