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: DetectContentType does not detect image/svg+xml #47492

Closed
brabiega opened this issue Aug 1, 2021 · 3 comments
Closed

net/http: DetectContentType does not detect image/svg+xml #47492

brabiega opened this issue Aug 1, 2021 · 3 comments

Comments

@brabiega
Copy link

brabiega commented Aug 1, 2021

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

$ go version
go version go1.16.6 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build996188498=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Get some svg document (e.g. create new one with Inkscape), save it as example.svg

package main

import "fmt"
import "net/http"
import "io/ioutil"

func main() {
    body, _ := ioutil.ReadFile("example.svg")
    res := http.DetectContentType(body)
    fmt.Println(res)
}

What did you expect to see?

image/svg+xml; charset=utf-8

What did you see instead?

text/xml; charset=utf-8

Standalone SVG documents aren't properly recognized.
https://www.w3.org/TR/SVG2/conform.html#DocumentConformanceClasses

Example of SVG document

root@machine:~# head -n 10 example.svg 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink"
@seankhliao
Copy link
Member

Duplicate of #15888

@seankhliao seankhliao marked this as a duplicate of #15888 Aug 1, 2021
@brabiega
Copy link
Author

brabiega commented Aug 2, 2021

Hello,
So.. this issue is not solved. Content type is detected incorrectly.
At least a word of comment in the documentation that this method is not reliable and may not work as expected?

@seankhliao
Copy link
Member

The documentation is clear in that it only returns those defined by https://mimesniff.spec.whatwg.org/

@golang golang locked and limited conversation to collaborators Aug 2, 2022
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

3 participants