From c1abfb584f78a7d2a6b6bc0ed0342d4e1f747911 Mon Sep 17 00:00:00 2001 From: Frank Massi Date: Wed, 25 Jan 2023 09:55:29 -0600 Subject: [PATCH 1/2] Fix populateUrl with param before a slash The regex match was too greedy when the param was in the middle of the url. This deals with end-of-string params first, and then handles the pre-slash params, preserving the slash. --- runtime/utils/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime/utils/index.js b/runtime/utils/index.js index ef451525..33dc3549 100644 --- a/runtime/utils/index.js +++ b/runtime/utils/index.js @@ -148,8 +148,12 @@ export function populateUrl(path, params, inheritedParams) { const allParams = Object.assign({}, inheritedParams, params) const queryString = getQueryString(path, params) - for (const [key, value] of Object.entries(allParams)) - path = path.replace(new RegExp(`:${key}(\/|$)`), value) + for (const [key, value] of Object.entries(allParams)) { + if (path.endsWith(`:${key}`)) { + path = path.replace(new RegExp(`:${key}($)`), value) + } + path = path.replace(new RegExp(`:${key}(\/)`), `${value}/`) + } return `${path}${queryString}` } From b70380c2014657bab5d242925fd4df494d39133f Mon Sep 17 00:00:00 2001 From: Frank Massi Date: Wed, 25 Jan 2023 10:26:35 -0600 Subject: [PATCH 2/2] PR feedback - better regex for trailing slash handling --- runtime/utils/index.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/runtime/utils/index.js b/runtime/utils/index.js index 33dc3549..e9500577 100644 --- a/runtime/utils/index.js +++ b/runtime/utils/index.js @@ -148,12 +148,8 @@ export function populateUrl(path, params, inheritedParams) { const allParams = Object.assign({}, inheritedParams, params) const queryString = getQueryString(path, params) - for (const [key, value] of Object.entries(allParams)) { - if (path.endsWith(`:${key}`)) { - path = path.replace(new RegExp(`:${key}($)`), value) - } - path = path.replace(new RegExp(`:${key}(\/)`), `${value}/`) - } + for (const [key, value] of Object.entries(allParams)) + path = path.replace(new RegExp(`:${key}(\/|$)`), value + "$1") return `${path}${queryString}` }