Skip to content

Commit

Permalink
PR feedback - better regex for trailing slash handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fdm1 committed Jan 25, 2023
1 parent c1abfb5 commit b70380c
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions runtime/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}
Expand Down

0 comments on commit b70380c

Please sign in to comment.