]> Cypherpunks repositories - gostls13.git/commitdiff
net/url: report first error from ParseQuery.
authorDavid Symonds <dsymonds@golang.org>
Mon, 8 Oct 2012 21:10:32 +0000 (08:10 +1100)
committerDavid Symonds <dsymonds@golang.org>
Mon, 8 Oct 2012 21:10:32 +0000 (08:10 +1100)
Fixes #4175.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6610068

src/pkg/net/url/url.go
src/pkg/net/url/url_test.go

index 7b9289468bf482b772462627526df08bc246adbc..d1fff89da79609548fc5cef9bac233e2251a1b18 100644 (file)
@@ -521,12 +521,16 @@ func parseQuery(m Values, query string) (err error) {
                }
                key, err1 := QueryUnescape(key)
                if err1 != nil {
-                       err = err1
+                       if err == nil {
+                               err = err1
+                       }
                        continue
                }
                value, err1 = QueryUnescape(value)
                if err1 != nil {
-                       err = err1
+                       if err == nil {
+                               err = err1
+                       }
                        continue
                }
                m[key] = append(m[key], value)
index 9ea8d7ecd120671efce724b45b49d1b04e917694..64f11700278c1bc750454d7ac5376c9df03ee3a8 100644 (file)
@@ -7,6 +7,7 @@ package url
 import (
        "fmt"
        "reflect"
+       "strings"
        "testing"
 )
 
@@ -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")
+       }
+}