From dd2e13556020cea3daae2278bec4e9870578384b Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Tue, 21 Feb 2017 21:54:38 +0100 Subject: [PATCH] test: add two test cases for querystring + Check an empty substring: In `querystring`, if the `maxKeys` is 1 and the state machine finds an empty substring between separators, it should return an empty object. + Test invalid encoded strings: If provided string is an invalid encoded string in `query.parse`, it will not be encoded. PR-URL: https://github.com/nodejs/node/pull/11481 Reviewed-By: Timothy Gu Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/parallel/test-querystring.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index 5b6c06958a..51332d59a7 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -288,6 +288,11 @@ assert.strictEqual( Object.keys(qs.parse('a=1&b=1&c=1', null, null, { maxKeys: 1 })).length, 1); +// Test limiting with a case that starts from `&` +assert.strictEqual( + Object.keys(qs.parse('&a', null, null, { maxKeys: 1 })).length, + 0); + // Test removing limit function testUnlimitedKeys() { const query = {}; @@ -334,6 +339,8 @@ assert.strictEqual(qs.unescapeBuffer('a%20').toString(), 'a '); assert.strictEqual(qs.unescapeBuffer('a%2g').toString(), 'a%2g'); assert.strictEqual(qs.unescapeBuffer('a%%').toString(), 'a%%'); +// Test invalid encoded string +check(qs.parse('%\u0100=%\u0101'), { '%Ā': '%ā' }); // Test custom decode function demoDecode(str) {