Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path.test fails to match when query params are omitted #50

Open
enochcheung opened this issue Apr 15, 2020 · 0 comments
Open

Path.test fails to match when query params are omitted #50

enochcheung opened this issue Apr 15, 2020 · 0 comments

Comments

@enochcheung
Copy link

When query parameters are specified in the path pattern, it does not match paths that omit all query parameters

import { Path } from 'path-parser';

const path = new Path('/foo?:bar');

// Returns {bar: 1} as expected
console.log(path.test('/foo?bar=1'));

// Fails to match, returns null. I expect this to return {foo: undefined}
console.log(path.test('/foo'));

Seems like the reason this is happening is that the full path is passed into search-string for query param parsing (

const queryParams = parseQueryParams(path, options.queryParams)
). For path /foo, search-string will try to interpret /foo as a query param key, and end up returning {'/foo': null}. This causes path matching to fail, because /foo is an unexpected key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant