From 7168049bd2b9b0000ea1ea46108c46e22ef57a37 Mon Sep 17 00:00:00 2001 From: Aleksey Leshko Date: Sun, 20 Oct 2019 17:19:27 +0300 Subject: [PATCH] fix(buildQuery): support params without key closes #243 #383 --- src/URI.js | 2 +- test/test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/URI.js b/src/URI.js index cb52699e..8b0c24d6 100644 --- a/src/URI.js +++ b/src/URI.js @@ -744,7 +744,7 @@ var t = ''; var unique, key, i, length; for (key in data) { - if (hasOwn.call(data, key) && key) { + if (hasOwn.call(data, key)) { if (isArray(data[key])) { unique = {}; for (i = 0, length = data[key].length; i < length; i++) { diff --git a/test/test.js b/test/test.js index c29c2ad1..716ec761 100644 --- a/test/test.js +++ b/test/test.js @@ -1321,6 +1321,9 @@ u.query('?&foo=bar&foo=bar').normalizeQuery(); equal(u.query(), 'foo=bar', 'duplicate key=value resolution'); + + u.query('?=bar').normalizeQuery(); + equal(u.query(), '=bar', 'query without key'); }); test('normalizeFragment', function() { var u = new URI('http://example.org/foobar.html#'); @@ -1330,6 +1333,9 @@ test('readable', function() { var u = new URI('http://foo:bar@www.xn--exmple-cua.org/hello%20world/ä.html?foo%5B%5D=b+är#fragment'); equal(u.readable(), 'http://www.exämple.org/hello world/ä.html?foo[]=b är#fragment', 'readable URL'); + + var u = new URI('http://example.org/?=5640'); + equal(u.readable(), 'http://example.org/?=5640', 'readable URL: query without key'); }); module('resolving URLs');