You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the http.DetectContentType to get the content type of a html file that starts with these lines:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
...
So I call http.DetectContentType passing the first 512 bytes of the file.
As after <!DOCTYPE html we have a \n character, the content type returned by the function is text/plain; charset=utf-8.
Apparently because the isTT function is not considering line-feed characters as a tag-termination byte and is returning false when matching the file content with the html signature string:
// isTT reports whether the provided byte is a tag-terminating byte (0xTT)
// as defined in https://mimesniff.spec.whatwg.org/#terminology.
func isTT(b byte) bool {
switch b {
case ' ', '>':
return true
}
return false
}
What did you expect to see?
The correct content type returned should be text/xml; charset=utf-8 .
The text was updated successfully, but these errors were encountered:
Go version
go version 1.23.5
Output of
go env
in your module/workspace:What did you do?
I'm using the http.DetectContentType to get the content type of a html file that starts with these lines:
So I call http.DetectContentType passing the first 512 bytes of the file.
I shared this go.play link to help to reproduce the issue: https://go.dev/play/p/cM_Wy5pEiYT
What did you see happen?
As after
<!DOCTYPE html
we have a\n
character, the content type returned by the function istext/plain; charset=utf-8
.Apparently because the
isTT
function is not considering line-feed characters as a tag-termination byte and is returning false when matching the file content with the html signature string:What did you expect to see?
The correct content type returned should be
text/xml; charset=utf-8
.The text was updated successfully, but these errors were encountered: