URLs with encoded characters
jjuutila opened this issue · comments
I would like to hear your thoughts how to solve a problem with percent encoded characters in an URL. The following example illustrates what I'm trying to get working:
const RouteNode = require('route-node')
const rootNode = new RouteNode('', '', [{
name: 'product-page',
path: '/:productName<.+>/:productId<(\\w{2}[0-9]{4})>.html'
}])
const matchedPath = rootNode.matchPath('/something-%21-%23-%24-%25-/B41680.html')
console.log('matchedPath', matchedPath)
rootNode.matchPath
returns null
because segment
has an encoded value and consumedPath
has the same value but it is decoded (it is decoded in path-parser
). See the code here: https://github.com/troch/route-node/blob/master/modules/matchChildren.ts#L64
Do you think I should just do decodeURIComponent(segment)
?
I am also facing an issue with encoded characters in the URL, but in our case it's breaking our links. We run every link clicked through the matchUrl function because we have different logic for defined routes, external resource, and internal resources. So URLs with encoded characters and up failing and nothing happens when you click on them.
For example, this URL works fine:
./test-file(parentheses).pdf
But when encoded it does not:
./test-file%28parentheses%29.pdf
Issue seems to be that the "remainingPath" variable ends up undefined here:
remainingPath = getPath(remainingPath) + (querystring ?
?${querystring} : '')
Could there be a fallback in place to make sure that variable always gets set to something at least?
Also having issues with url encoding. Any update on this? @troch