aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/util.js13
-rw-r--r--tests/test-util.js7
2 files changed, 8 insertions, 12 deletions
diff --git a/lib/util.js b/lib/util.js
index d8da1e5..77b7fac 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -39,21 +39,21 @@ exports.heir = function heir(p) {
*/
var getParamsFromURL = exports.getParamsFromURL = function getParamsFromURL (url) {
if (!url || (url.toString().length === 0)) {
- return null;
+ throw new Error("Missing URL value!");
}
if (!(url instanceof urlMod.URL)) {
url = new urlMod.URL(url.toString());
}
- if (url.path === "/") {
- return null;
+ var paramsArr = url.path.split("?");
+ if (paramsArr.length === 1) {
+ return {};
}
- var paramsArr = url.path.split("?")[1].split('&');
// get convert URL parameters to an Object
var params = {}, s = [];
- paramsArr.forEach(function(par) {
+ paramsArr[1].split('&').forEach(function(par) {
s = par.split('=');
params[s[0]] = s[1];
});
@@ -61,9 +61,6 @@ var getParamsFromURL = exports.getParamsFromURL = function getParamsFromURL (url
};
exports.getBugNo = function getBugNo(url) {
- if (!url) {
- throw new Error("Missing URL value!");
- }
var params = getParamsFromURL(url);
if (params && params.id) {
return parseInt(params.id, 10);
diff --git a/tests/test-util.js b/tests/test-util.js
index fcf840c..f420bb4 100644
--- a/tests/test-util.js
+++ b/tests/test-util.js
@@ -199,11 +199,10 @@ exports.ensureGetParamsFromURL = function (test) {
}),
"simply compare result of bugzilla show_page URL");
test.assertEqual(JSON.stringify(util.getParamsFromURL("https://bugzilla.redhat.com/")),
- JSON.stringify(null),
+ JSON.stringify({}),
"URL without any parameters");
- test.assertEqual(JSON.stringify(util.getParamsFromURL("")),
- JSON.stringify(null),
- "no URL");
+ test.assertRaises(function () {util.getParamsFromURL("")},
+ "Missing URL value!", "No URL");
};
// testing util.getBugNo