From b218599906af51421ae6d6e6f4a8299cb6a468ea Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Tue, 28 Feb 2017 12:04:29 -0800 Subject: [PATCH] Fixed #864 (#865) Signed-off-by: Vishal Rana --- bind.go | 2 +- bind_test.go | 4 +++- echo.go | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bind.go b/bind.go index f2393ea6..010401fc 100644 --- a/bind.go +++ b/bind.go @@ -51,7 +51,7 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) { return NewHTTPError(http.StatusBadRequest, err.Error()) } } - case strings.HasPrefix(ctype, MIMEApplicationXML): + case strings.HasPrefix(ctype, MIMEApplicationXML), strings.HasPrefix(ctype, MIMETextXML): if err = xml.NewDecoder(req.Body).Decode(i); err != nil { if ute, ok := err.(*xml.UnsupportedTypeError); ok { return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unsupported type error: type=%v, error=%v", ute.Type, ute.Error())) diff --git a/bind_test.go b/bind_test.go index 8ba0781b..64219fc3 100644 --- a/bind_test.go +++ b/bind_test.go @@ -96,6 +96,8 @@ func TestBindJSON(t *testing.T) { func TestBindXML(t *testing.T) { testBindOkay(t, strings.NewReader(userXML), MIMEApplicationXML) testBindError(t, strings.NewReader(invalidContent), MIMEApplicationXML) + testBindOkay(t, strings.NewReader(userXML), MIMETextXML) + testBindError(t, strings.NewReader(invalidContent), MIMETextXML) } func TestBindForm(t *testing.T) { @@ -292,7 +294,7 @@ func testBindError(t *testing.T, r io.Reader, ctype string) { err := c.Bind(u) switch { - case strings.HasPrefix(ctype, MIMEApplicationJSON), strings.HasPrefix(ctype, MIMEApplicationXML), + case strings.HasPrefix(ctype, MIMEApplicationJSON), strings.HasPrefix(ctype, MIMEApplicationXML), strings.HasPrefix(ctype, MIMETextXML), strings.HasPrefix(ctype, MIMEApplicationForm), strings.HasPrefix(ctype, MIMEMultipartForm): if assert.IsType(t, new(HTTPError), err) { assert.Equal(t, http.StatusBadRequest, err.(*HTTPError).Code) diff --git a/echo.go b/echo.go index 94761228..45667a9e 100644 --- a/echo.go +++ b/echo.go @@ -145,6 +145,8 @@ const ( MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8 + MIMETextXML = "text/xml" + MIMETextXMLCharsetUTF8 = MIMETextXML + "; " + charsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack"