From ed387356811110f8a63738051121ae0893898276 Mon Sep 17 00:00:00 2001 From: Markus Ast Date: Tue, 23 Jun 2020 21:18:32 +0200 Subject: Fix deserializing empty sequences (#31) --- src/de/parse.rs | 5 +++++ tests/test_deserialize.rs | 9 +++++++++ 2 files changed, 14 insertions(+) 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"[""]); -- cgit v1.2.3