Skip to content

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

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

Closed
guliyevemil1 opened this issue Jun 7, 2018 · 1 comment
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge

Comments

@guliyevemil1
Copy link

guliyevemil1 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
@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label Jun 7, 2018
@agnivade
Copy link
Contributor

agnivade 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 as completed 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.
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

3 participants