Commit c7cc894e authored by David Symonds's avatar David Symonds

net/url: report first error from ParseQuery.

Fixes #4175.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6610068
parent c81293ad
...@@ -521,12 +521,16 @@ func parseQuery(m Values, query string) (err error) { ...@@ -521,12 +521,16 @@ func parseQuery(m Values, query string) (err error) {
} }
key, err1 := QueryUnescape(key) key, err1 := QueryUnescape(key)
if err1 != nil { if err1 != nil {
err = err1 if err == nil {
err = err1
}
continue continue
} }
value, err1 = QueryUnescape(value) value, err1 = QueryUnescape(value)
if err1 != nil { if err1 != nil {
err = err1 if err == nil {
err = err1
}
continue continue
} }
m[key] = append(m[key], value) m[key] = append(m[key], value)
......
...@@ -7,6 +7,7 @@ package url ...@@ -7,6 +7,7 @@ package url
import ( import (
"fmt" "fmt"
"reflect" "reflect"
"strings"
"testing" "testing"
) )
...@@ -779,3 +780,13 @@ func TestRequestURI(t *testing.T) { ...@@ -779,3 +780,13 @@ func TestRequestURI(t *testing.T) {
} }
} }
} }
func TestParseFailure(t *testing.T) {
// Test that the first parse error is returned.
const url = "%gh&%ij"
_, err := ParseQuery(url)
errStr := fmt.Sprint(err)
if !strings.Contains(errStr, "%gh") {
t.Errorf(`ParseQuery(%q) returned error %q, want something containing %q"`, url, errStr, "%gh")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment