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

net/http: content type detection does not work correctly for some documents that start with HTML comments #25771

Closed
guliyevemil1 opened this issue Jun 7, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@guliyevemil1
Copy link

commented Jun 7, 2018

Some website documents start with "<!--[if IE]" or "<--comment with no space" and some close it without leaving an actual comment like this: "<!--->".

None of these cases are detected correctly because "<!--" htmlSig is treated like a regular HTML tag when in reality behaves slightly differently.

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

❯ go version
go version go1.10.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

❯ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"

What did you do?

package main

import (
	"fmt"
	"net/http"
)

func main() {
	fmt.Println(http.DetectContentType([]byte(`<!--[if !IE]> This has been served from cache <![endif]--><html><body>Hello,world</body></html>`)))
	fmt.Println(http.DetectContentType([]byte(`<!-- [if !IE]> This has been served from cache <![endif]--><html><body>Hello,world</body></html>`)))
}

https://play.golang.org/p/f6-N3OA9FGU

What did you expect to see?

text/html; charset=utf-8
text/html; charset=utf-8

What did you see instead?

text/plain; charset=utf-8
text/html; charset=utf-8

@guliyevemil1 guliyevemil1 changed the title net/http: content type detection does not work correctly for HTML comments net/http: content type detection does not work correctly for some documents that start with HTML comments Jun 7, 2018

@agnivade

This comment has been minimized.

Copy link
Member

commented Jun 7, 2018

We follow the algorithm laid out at http://mimesniff.spec.whatwg.org/. According to it, the string <!-- must be followed by a tag-terminating byte. A tag terminating byte is either a space or closing angle bracket.

So this is working as intended. If you want this changed, I would suggest raising an issue at https://github.com/whatwg/mimesniff.

@agnivade agnivade closed this Jun 7, 2018

@golang golang locked and limited conversation to collaborators Jun 7, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.