From fe3e4196872b8ea6e49be1dec2e7fff72432abda Mon Sep 17 00:00:00 2001 From: cloudhead Date: Thu, 5 Aug 2010 03:13:40 -0400 Subject: [PATCH] querystring.parse: handle undefined value properly --- lib/querystring.js | 1 + test/simple/test-querystring.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/querystring.js b/lib/querystring.js index ba2b1cc9dc..69ea008548 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -77,6 +77,7 @@ var chunks = /(?:(?:^|\.)([^\[\(\.]+)(?=\[|\.|$|\()|\[([^"'][^\]]*?)\]|\["([^\]" // Parse a key=val string. QueryString.parse = QueryString.decode = function (qs, sep, eq) { var obj = {}; + if (qs === undefined) { return {} } String(qs).split(sep || "&").map(function (keyValue) { var res = obj, next, diff --git a/test/simple/test-querystring.js b/test/simple/test-querystring.js index e1598465ff..0470b467f7 100644 --- a/test/simple/test-querystring.js +++ b/test/simple/test-querystring.js @@ -165,3 +165,6 @@ var f = qs.stringify({ }, ";", ":") }, ";", ":"); assert.equal(f, "a:b;q:x%3Ay%3By%3Az"); + + +assert.deepEqual({}, qs.parse());