diff options
author | Markus Ast <m@rkusa.st> | 2020-06-23 21:18:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-23 15:18:32 -0400 |
commit | ed387356811110f8a63738051121ae0893898276 (patch) | |
tree | d8293b117f2c5dce6c68592a10409b920e1a7562 | |
parent | 165b80ddd4736ac0e89130bc8a30d714b9a8e6c1 (diff) |
Fix deserializing empty sequences (#31)
-rw-r--r-- | src/de/parse.rs | 5 | ||||
-rw-r--r-- | tests/test_deserialize.rs | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/de/parse.rs b/src/de/parse.rs index ffd1a3f..75ae134 100644 --- a/src/de/parse.rs +++ b/src/de/parse.rs @@ -333,6 +333,11 @@ impl<'a> Parser<'a> { } } } + // Skip empty byte sequences (e.g. leading `&`, trailing `&`, `&&`, ...) + b'&' => { + self.clear_acc(); + Ok(true) + } // This means the key should be a root key // of the form "abc" or "abc[..=]" // We do actually allow integer keys here since they cannot diff --git a/tests/test_deserialize.rs b/tests/test_deserialize.rs index bac2948..8d518ee 100644 --- a/tests/test_deserialize.rs +++ b/tests/test_deserialize.rs @@ -124,6 +124,12 @@ fn qs_test_simple() { // st.deepEqual(qs.parse('0=foo'), { 0: 'foo' }); map_test!("0=foo", 0["foo"]); + // st.deepEqual(qs.parse('&0=foo'), { 0: 'foo' }); + map_test!("&0=foo", 0["foo"]); + + // st.deepEqual(qs.parse('0=foo&'), { 0: 'foo' }); + map_test!("0=foo&", 0["foo"]); + // st.deepEqual(qs.parse('foo=c++'), { foo: 'c ' }); map_test!("foo=c++", "foo"["c "]); @@ -159,6 +165,9 @@ fn qs_test_simple() { // st.deepEqual(qs.parse('foo=bar&bar=baz'), { foo: 'bar', bar: 'baz' }); map_test!("foo=bar&bar=baz", "foo"["bar"] "bar"["baz"]); + // st.deepEqual(qs.parse('foo=bar&&bar=baz'), { foo: 'bar', bar: 'baz' }); + map_test!("foo=bar&&bar=baz", "foo"["bar"] "bar"["baz"]); + // st.deepEqual(qs.parse('foo2=bar2&baz2='), { foo2: 'bar2', baz2: '' }); map_test!("foo2=bar2&baz2=", "foo2"["bar2"] "baz2"[""]); |