diff options
author | Wolfy-J <[email protected]> | 2018-06-12 18:34:30 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-12 18:34:30 +0300 |
commit | 18b2cb4a9b1a8a22ab260d2a0a611765f8e113a3 (patch) | |
tree | 5ce4c4490c0920a8ee392bce450dc7f1183a691c | |
parent | 9980f8a1a4f8c2aebd8e40a8e892bda4bf734eb0 (diff) |
tests!
-rw-r--r-- | service/http/parse.go | 30 | ||||
-rw-r--r-- | service/http/server_test.go | 3 |
2 files changed, 8 insertions, 25 deletions
diff --git a/service/http/parse.go b/service/http/parse.go index 96ffcdcc..0224af41 100644 --- a/service/http/parse.go +++ b/service/http/parse.go @@ -31,23 +31,14 @@ func parseData(r *http.Request) (dataTree, error) { // pushes value into data tree. func (d dataTree) push(k string, v []string) { - if len(v) == 0 { - // skip empty values - return - } - - indexes := fetchIndexes(k) - if len(indexes) <= MaxLevel { - d.mount(indexes, v) + keys := fetchIndexes(k) + if len(keys) <= MaxLevel { + d.mount(keys, v) } } // mount mounts data tree recursively. func (d dataTree) mount(i []string, v []string) { - if len(v) == 0 { - return - } - if len(i) == 1 { // single value context d[i[0]] = v[0] @@ -106,23 +97,14 @@ func exists(path string) bool { // pushes new file upload into it's proper place. func (d fileTree) push(k string, v []*FileUpload) { - if len(v) == 0 { - // skip empty values - return - } - - indexes := fetchIndexes(k) - if len(indexes) <= MaxLevel { - d.mount(indexes, v) + keys := fetchIndexes(k) + if len(keys) <= MaxLevel { + d.mount(keys, v) } } // mount mounts data tree recursively. func (d fileTree) mount(i []string, v []*FileUpload) { - if len(v) == 0 { - return - } - if len(i) == 1 { // single value context d[i[0]] = v[0] diff --git a/service/http/server_test.go b/service/http/server_test.go index ed238c58..1f65e6d3 100644 --- a/service/http/server_test.go +++ b/service/http/server_test.go @@ -339,6 +339,7 @@ func TestServer_FormData_POST(t *testing.T) { form.Add("arr[x][y][z]", "y") form.Add("arr[x][y][e]", "f") form.Add("arr[c]p", "l") + form.Add("arr[c]z", "") req, err := http.NewRequest( "POST", @@ -359,5 +360,5 @@ func TestServer_FormData_POST(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 200, r.StatusCode) - assert.Equal(t, `{"arr":{"c":{"p":"l"},"x":{"y":{"e":"f","z":"y"}}},"key":"value","name":["name1","name2","name3"]}`, string(b)) + assert.Equal(t, `{"arr":{"c":{"p":"l","z":""},"x":{"y":{"e":"f","z":"y"}}},"key":"value","name":["name1","name2","name3"]}`, string(b)) } |