aboutsummaryrefslogtreecommitdiff
path: root/args_test.go
diff options
context:
space:
mode:
authorGravatar xuecai <bluesnow1st@sina.com> 2018-12-31 02:56:58 +0800
committerGravatar Erik Dubbelboer <erik@dubbelboer.com> 2018-12-30 19:56:58 +0100
commit4fb459a45e393f97a4c90cf3e2492f015f1447f9 (patch)
treee99eb3d45d6c991ab7b648b467ea2e2451eabbdb /args_test.go
parentAdd RequestHeader.VisitAllInOrder (diff)
downloadfasthttp-4fb459a45e393f97a4c90cf3e2492f015f1447f9.tar.gz
fasthttp-4fb459a45e393f97a4c90cf3e2492f015f1447f9.tar.bz2
fasthttp-4fb459a45e393f97a4c90cf3e2492f015f1447f9.zip
fix args empty string be changed to boolen (#502)
Add support for empty args
Diffstat (limited to 'args_test.go')
-rw-r--r--args_test.go28
1 files changed, 19 insertions, 9 deletions
diff --git a/args_test.go b/args_test.go
index 217952a..2a5cb9a 100644
--- a/args_test.go
+++ b/args_test.go
@@ -37,22 +37,24 @@ func TestArgsAdd(t *testing.T) {
a.Add("foo", "baz")
a.Add("foo", "1")
a.Add("ba", "23")
- if a.Len() != 4 {
- t.Fatalf("unexpected number of elements: %d. Expecting 4", a.Len())
+ a.Add("foo", "")
+ a.AddNoValue("foo")
+ if a.Len() != 6 {
+ t.Fatalf("unexpected number of elements: %d. Expecting 6", a.Len())
}
s := a.String()
- expectedS := "foo=bar&foo=baz&foo=1&ba=23"
+ expectedS := "foo=bar&foo=baz&foo=1&ba=23&foo=&foo"
if s != expectedS {
t.Fatalf("unexpected result: %q. Expecting %q", s, expectedS)
}
var a1 Args
a1.Parse(s)
- if a1.Len() != 4 {
- t.Fatalf("unexpected number of elements: %d. Expecting 4", a.Len())
+ if a1.Len() != 6 {
+ t.Fatalf("unexpected number of elements: %d. Expecting 6", a.Len())
}
- var barFound, bazFound, oneFound, baFound bool
+ var barFound, bazFound, oneFound, emptyFound1, emptyFound2, baFound bool
a1.VisitAll(func(k, v []byte) {
switch string(k) {
case "foo":
@@ -63,6 +65,12 @@ func TestArgsAdd(t *testing.T) {
bazFound = true
case "1":
oneFound = true
+ case "":
+ if emptyFound1 {
+ emptyFound2 = true
+ } else {
+ emptyFound1 = true
+ }
default:
t.Fatalf("unexpected value %q", v)
}
@@ -75,8 +83,8 @@ func TestArgsAdd(t *testing.T) {
t.Fatalf("unexpected key found %q", k)
}
})
- if !barFound || !bazFound || !oneFound || !baFound {
- t.Fatalf("something is missing: %v, %v, %v, %v", barFound, bazFound, oneFound, baFound)
+ if !barFound || !bazFound || !oneFound || !emptyFound1 || !emptyFound2 || !baFound {
+ t.Fatalf("something is missing: %v, %v, %v, %v, %v, %v", barFound, bazFound, oneFound, emptyFound1, emptyFound2, baFound)
}
}
@@ -303,10 +311,12 @@ func TestArgsStringCompose(t *testing.T) {
a.Set("foo", "bar")
a.Set("aa", "bbb")
a.Set("привет", "мир")
+ a.SetNoValue("bb")
a.Set("", "xxxx")
a.Set("cvx", "")
+ a.SetNoValue("novalue")
- expectedS := "foo=bar&aa=bbb&%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82=%D0%BC%D0%B8%D1%80&=xxxx&cvx"
+ expectedS := "foo=bar&aa=bbb&%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82=%D0%BC%D0%B8%D1%80&bb&=xxxx&cvx=&novalue"
s := a.String()
if s != expectedS {
t.Fatalf("Unexpected string %q. Exected %q", s, expectedS)