radix3
radix3 copied to clipboard
router lookup ** not matching ""
Environment
node 20 and bun
Reproduction
const router = createRouter();
router.insert("/test/**:test", { payload: "wildcard" });
console.log([
router.lookup("/test")
]);
output: [ null ]
expected: [ { payload: 'wildcard', params: { test: '' } } ]
Describe the bug
router does not match **
as nothing instead requires some value
Additional context
This does only happen when **
is not the only part.
/**
does match /
but
/test/**
does not match /test/
This behavior is not present in the matcher
for the matcher there are also tests that check if **
matches ""
possible fix
I also played around a bit and tried fixing it myself and ended up with this addition to the lookup()
function:
if (node && node.data == null && node.wildcardChildNode) {
node = node.wildcardChildNode;
params[node.paramName || "_"] = "";
paramsFound = true;
}
tbh I do not completely understand how the lookup works that's why I am not opening a PR right now
Logs
No response