Skip to content

Commit

Permalink
Merge pull request #664 from suzaku/simplify
Browse files Browse the repository at this point in the history
len(k) is guaranteed to be greater than 1 in this case
  • Loading branch information
dhui committed Dec 8, 2021
2 parents ca2d3e0 + 169d0fc commit 0c500eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion util.go
Expand Up @@ -53,7 +53,7 @@ func FilterCustomQuery(u *nurl.URL) *nurl.URL {
ux := *u
vx := make(nurl.Values)
for k, v := range ux.Query() {
if len(k) <= 1 || (len(k) > 1 && k[0:2] != "x-") {
if len(k) <= 1 || k[0:2] != "x-" {
vx[k] = v
}
}
Expand Down
5 changes: 4 additions & 1 deletion util_test.go
Expand Up @@ -21,12 +21,15 @@ func TestSuint(t *testing.T) {
}

func TestFilterCustomQuery(t *testing.T) {
n, err := nurl.Parse("foo://host?a=b&x-custom=foo&c=d")
n, err := nurl.Parse("foo://host?a=b&x-custom=foo&c=d&ok=y")
if err != nil {
t.Fatal(err)
}
nx := FilterCustomQuery(n).Query()
if nx.Get("x-custom") != "" {
t.Fatalf("didn't expect x-custom")
}
if nx.Get("ok") != "y" {
t.Fatalf("expected ok=y, got %v", nx.Get("ok"))
}
}

0 comments on commit 0c500eb

Please sign in to comment.