basic validation added to router utils path param

This commit is contained in:
NikolaBorislavovHristov 2019-09-02 11:30:07 +03:00
parent 8fe3b1ae69
commit 0a97a9be9a
3 changed files with 9 additions and 6 deletions

View file

@ -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;

View file

@ -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;
}
}
}
}

View file

@ -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];