aboutsummaryrefslogtreecommitdiffhomepage
path: root/http
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2019-09-18 22:12:15 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2019-09-18 22:32:29 -0700
commitca48f7612ada5d64d1097c40321a919eb28eb2bf (patch)
treea67f60a72f35168b4d0594c17cae26da424ff7b1 /http
parent7d50cc40de4487eba3da5635ba85cc2e956bad98 (diff)
Ignore invalid content type
Diffstat (limited to 'http')
-rw-r--r--http/client/response.go10
-rw-r--r--http/client/response_test.go3
2 files changed, 4 insertions, 9 deletions
diff --git a/http/client/response.go b/http/client/response.go
index 0e918b5..e62b5ab 100644
--- a/http/client/response.go
+++ b/http/client/response.go
@@ -8,7 +8,6 @@ import (
"bytes"
"io"
"io/ioutil"
- "mime"
"regexp"
"strings"
"unicode/utf8"
@@ -74,17 +73,12 @@ func (r *Response) IsModified(etag, lastModified string) bool {
// - Feeds with wrong encoding defined and already in UTF-8
func (r *Response) EnsureUnicodeBody() (err error) {
if r.ContentType != "" {
- mediaType, _, mediaErr := mime.ParseMediaType(r.ContentType)
- if mediaErr != nil {
- return mediaErr
- }
-
// JSON feeds are always in UTF-8.
- if strings.Contains(mediaType, "json") {
+ if strings.Contains(r.ContentType, "json") {
return
}
- if strings.Contains(mediaType, "xml") {
+ if strings.Contains(r.ContentType, "xml") {
buffer, _ := ioutil.ReadAll(r.Body)
r.Body = bytes.NewReader(buffer)
diff --git a/http/client/response_test.go b/http/client/response_test.go
index 37f6faf..818fd81 100644
--- a/http/client/response_test.go
+++ b/http/client/response_test.go
@@ -121,6 +121,7 @@ func TestEnsureUnicodeWithHTMLDocuments(t *testing.T) {
{"urdu.xml", "text/xml; charset=utf-8", true},
{"content-type-only-win-8859-1.xml", "application/xml; charset=ISO-8859-1", true},
{"rdf_utf8.xml", "application/rss+xml; charset=utf-8", true},
+ {"rdf_utf8.xml", "application/rss+xml; charset: utf-8", true}, // Invalid Content-Type
{"charset-content-type-xml-iso88591.xml", "application/rss+xml; charset=ISO-8859-1", false},
{"windows_1251.xml", "text/xml", false},
{"smallfile.xml", "text/xml; charset=utf-8", true},
@@ -136,7 +137,7 @@ func TestEnsureUnicodeWithHTMLDocuments(t *testing.T) {
r := &Response{Body: bytes.NewReader(content), ContentType: tc.contentType}
parseErr := r.EnsureUnicodeBody()
if parseErr != nil {
- t.Fatalf(`Unicode conversion error for %q - %q: %v`, tc.filename, tc.contentType, err)
+ t.Fatalf(`Unicode conversion error for %q - %q: %v`, tc.filename, tc.contentType, parseErr)
}
isUnicode := utf8.ValidString(r.String())