Skip to content

Commit b218599

Browse files
authored
Fixed #864 (#865)
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 049518f commit b218599

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

bind.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
5151
return NewHTTPError(http.StatusBadRequest, err.Error())
5252
}
5353
}
54-
case strings.HasPrefix(ctype, MIMEApplicationXML):
54+
case strings.HasPrefix(ctype, MIMEApplicationXML), strings.HasPrefix(ctype, MIMETextXML):
5555
if err = xml.NewDecoder(req.Body).Decode(i); err != nil {
5656
if ute, ok := err.(*xml.UnsupportedTypeError); ok {
5757
return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unsupported type error: type=%v, error=%v", ute.Type, ute.Error()))

bind_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ func TestBindJSON(t *testing.T) {
9696
func TestBindXML(t *testing.T) {
9797
testBindOkay(t, strings.NewReader(userXML), MIMEApplicationXML)
9898
testBindError(t, strings.NewReader(invalidContent), MIMEApplicationXML)
99+
testBindOkay(t, strings.NewReader(userXML), MIMETextXML)
100+
testBindError(t, strings.NewReader(invalidContent), MIMETextXML)
99101
}
100102

101103
func TestBindForm(t *testing.T) {
@@ -292,7 +294,7 @@ func testBindError(t *testing.T, r io.Reader, ctype string) {
292294
err := c.Bind(u)
293295

294296
switch {
295-
case strings.HasPrefix(ctype, MIMEApplicationJSON), strings.HasPrefix(ctype, MIMEApplicationXML),
297+
case strings.HasPrefix(ctype, MIMEApplicationJSON), strings.HasPrefix(ctype, MIMEApplicationXML), strings.HasPrefix(ctype, MIMETextXML),
296298
strings.HasPrefix(ctype, MIMEApplicationForm), strings.HasPrefix(ctype, MIMEMultipartForm):
297299
if assert.IsType(t, new(HTTPError), err) {
298300
assert.Equal(t, http.StatusBadRequest, err.(*HTTPError).Code)

echo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ const (
145145
MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8
146146
MIMEApplicationXML = "application/xml"
147147
MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8
148+
MIMETextXML = "text/xml"
149+
MIMETextXMLCharsetUTF8 = MIMETextXML + "; " + charsetUTF8
148150
MIMEApplicationForm = "application/x-www-form-urlencoded"
149151
MIMEApplicationProtobuf = "application/protobuf"
150152
MIMEApplicationMsgpack = "application/msgpack"

0 commit comments

Comments
 (0)