Skip to content

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

Description

@enochcheung

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions