fix: the MIME type of an SVG file should be image/svg+xml#286
Conversation
Pull Request Test Coverage Report for Build 22859273349Details
💛 - Coveralls |
| if strings.HasSuffix(fileName, ext) { | ||
| tmp := t | ||
| if i := strings.Index(contentType, ";"); i != -1 { | ||
| if i := strings.Index(contentType, ";"); i != -1 && t != "image/svg+xml" { |
There was a problem hiding this comment.
Why do we need this condition?
There was a problem hiding this comment.
image/svg+xml usually does not need to be concatenated with charset=utf-8. If it exists, remove it.
There was a problem hiding this comment.
I see. This is because http.DetectContentType returns text/xml; charset=utf-8 and we want just image/svg+xml.
This is not necessary anymore since you added the SVG sniffing. Can you remove this change please?
| if strings.HasSuffix(fileName, ext) { | ||
| tmp := t | ||
| if i := strings.Index(contentType, ";"); i != -1 { | ||
| if i := strings.Index(contentType, ";"); i != -1 && t != "image/svg+xml" { |
There was a problem hiding this comment.
I see. This is because http.DetectContentType returns text/xml; charset=utf-8 and we want just image/svg+xml.
This is not necessary anymore since you added the SVG sniffing. Can you remove this change please?
| return strings.HasPrefix(content, "<svg") | ||
| } | ||
|
|
||
| func detectContentTypeByExtension(fileName, contentType string) string { |
There was a problem hiding this comment.
Please add an early return here if fileName is empty to avoid extra processing.
Co-authored-by: SystemGlitch <jeremy.la@outlook.fr>
Co-authored-by: SystemGlitch <jeremy.la@outlook.fr>
|
LGTM 👍🏻 I'll make a couple minor changes before merging. |
|
Merged 🎉 Thanks a lot! |
References
Issue(s): #xxx
Discussion: #yyy
Description
The MIME type of an SVG file should be image/svg+xml, otherwise, the front-end cannot render the image based on the MIME type.
Possible drawbacks