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

fix: quirk where a path with a query string would break matching #454

Merged
merged 2 commits into from
Jun 28, 2021

Conversation

erunion
Copy link
Member

@erunion erunion commented Jun 28, 2021

🧰 Changes

This fixes a quirk in our findOperation() method where if a path in the API definition had a query param (like ?param=123 it would completely kill the method because the ? was being interpreted as a regex modifier for path-to-regexp. To resolve this, I've loosened up matching on these kinds of paths so it'll look on /path instead of /path?param=123.

Fixes RM-1396

🧬 QA & Testing

I've added test cases for the initial regression as well as some other potential variants of this quirk.

@erunion erunion added the bug Something isn't working label Jun 28, 2021
@erunion erunion requested review from Dashron and kanadgupta June 28, 2021 16:24
Copy link
Member

@mjcuva mjcuva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code seems good to me!

@erunion erunion merged commit 874132a into main Jun 28, 2021
@erunion erunion deleted the fix/path-matching-quirks branch June 28, 2021 16:53
@@ -74,7 +74,13 @@ function normalizePath(path) {
// variable starts.
//
// For example if the URL is `/post/:param1::param2` we'll be escaping it to `/post/:param1\::param2`.
return path.replace(/{(.*?)}/g, ':$1').replace(/::/, '\\::');
return (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we could utilize the URL constructor here?

> new URL('/rating_stats?listing_ids[]=1234567', 'https://example.com').pathname
'/rating_stats'
> new URL('/people/GWID:3', 'https://example.com').pathname
'/people/GWID:3'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a bad idea. Will look into that after I get this fix up to the preview site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants