From 0a97a9be9aabb652aa24fc34da4e483336fde79d Mon Sep 17 00:00:00 2001 From: NikolaBorislavovHristov Date: Mon, 2 Sep 2019 11:30:07 +0300 Subject: [PATCH] basic validation added to router utils path param --- src/router/Router/queryParamsForQuery.js | 3 ++- src/router/Router/routeConfigForPath.js | 10 ++++++---- src/router/Router/urlParamsForPath.js | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/router/Router/queryParamsForQuery.js b/src/router/Router/queryParamsForQuery.js index a242aac39..ed5b19bb1 100644 --- a/src/router/Router/queryParamsForQuery.js +++ b/src/router/Router/queryParamsForQuery.js @@ -1,5 +1,6 @@ module.exports = (query) => { - return Array.from(new URLSearchParams(query).entries()) + const searchParams = new URLSearchParams(typeof query === 'string' ? query : ''); + return Array.from(searchParams.entries()) .reduce((result, [key, value]) => { result[key] = value; return result; diff --git a/src/router/Router/routeConfigForPath.js b/src/router/Router/routeConfigForPath.js index dc11bbf0f..841e3424d 100644 --- a/src/router/Router/routeConfigForPath.js +++ b/src/router/Router/routeConfigForPath.js @@ -1,8 +1,10 @@ module.exports = (viewsConfig, path) => { - for (const viewConfig of viewsConfig) { - for (const routeConfig of viewConfig) { - if (path.match(routeConfig.regexp)) { - return routeConfig; + if (typeof path === 'string') { + for (const viewConfig of viewsConfig) { + for (const routeConfig of viewConfig) { + if (path.match(routeConfig.regexp)) { + return routeConfig; + } } } } diff --git a/src/router/Router/urlParamsForPath.js b/src/router/Router/urlParamsForPath.js index a431c2801..d7b52aaea 100644 --- a/src/router/Router/urlParamsForPath.js +++ b/src/router/Router/urlParamsForPath.js @@ -1,5 +1,5 @@ module.exports = (routeConfig, path) => { - const matches = path.match(routeConfig.regexp); + const matches = typeof path === 'string' ? path.match(routeConfig.regexp) : []; return routeConfig.urlParamsNames.reduce((urlParams, name, index) => { if (Array.isArray(matches) && typeof matches[index + 1] === 'string') { urlParams[name] = matches[index + 1];