Skip to content

Commit

Permalink
Fixed #864 (#865)
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr authored Feb 28, 2017
1 parent 049518f commit b218599
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
4 changes: 3 additions & 1 deletion bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b218599

Please sign in to comment.