-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Query parameters cause invalid matches #209
Comments
There's also an option that lets you change the delimiter to |
I guess the point of the discussion I had was not explained correctly. Let's assume the regexp is created from this:
I get that Next, I want to test if a URL matches.
At this point, |
It makes sense, but you can adjust that using |
Taking a quick look now into some projects to see if changing the default would be possible or whether it would break existing applications. |
This is the suggested documentation update that came as part of issue pillarjs#209.
I didn't expect I also don't expect |
@fidian Did this come up in an application you're working on? The reason I'm clarifying is that, if you're using it for query params, it's possible others do rely on the matching behavior today. Can you share more about how you're using this package so I can understand how to better support it? |
Closing with 2ea948c. |
Thanks for the update! I'll still answer your question because it could be helpful to know how my team uses your library. I have a mock server built into a UI for testing purposes. It effectively has a list of patterns and the route handler.
When a mock request comes in, the routes are checked in order and the first one to handle the request will be used.
The breakdown is that the |
Do you find that it's good enough for query parameters that this package works for you? How are you handling (or not handling) out of order and extra parameters? |
The app I am using typically does not use query parameters and relies primarily on the body of the request. When it does use query parameters, they are in a predictable order. Due to the limited number and the predictable order, it is fairly easy to make rules for each route that would be used, so the library is working great. |
I'm aware that the ordering of query parameters is outside the scope of this project, as it clearly states in the README. However, this isn't about ordering. If the route ends with a parameter and it is followed by a query string, the parameter gets the
?
. Using the Node.js REPL, I can replicate this problem.The result of capturing
moo?
is broken. It appears that the regular expression constructed should look like the following.I would suggest updating the regular expression so the question mark can not be included in the path portion, which changes
(?:\/([^\/]+?))?
into(?:\/([^\/?]+?))?
. This should be done for safety, since question marks are technically not part of the path as per the RFC, section 3.Also, it would be nice to clearly update the documentation to indicate one of two positions:
If the path to parse contains query parameters, one must escape the question mark, changing
"/path?query=str"
into"/path\\?query=str"
(two backslashes = send a literal backslash). This isn't really explained in the optional section.Query strings are not supported at all and they must be removed before trying to parse the path. This appears to be the opinion stated in issues URL parameters behind a variable #47 and query parameters and RegExp's involving path parameter #91, but the documentation currently indicates that the library doesn't manage the ordering of query strings as opposed to query strings being forbidden.
The text was updated successfully, but these errors were encountered: