-
Notifications
You must be signed in to change notification settings - Fork 141
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
Adding feature ignoreDuplicateSlashes with tests #270
Adding feature ignoreDuplicateSlashes with tests #270
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for your contribution. I guess the main idea was to not match empty params, but not to remove duplicate slashes. I mean if someone decided to add a route with two slashes in a row we should match it.
Try to check if a parameter length is not equal to 0, how we check the maximum parameter length, and see if it works.
Line 446 in 2608f2b
if (decoded.length > maxParamLength) { |
Hi @ivan-tymoshenko, thanks for the quick reply 😄 I think you may have misunderstood #240. I filed it a couple months ago and the desired functionality was to remove duplicate sequential You can check the code example for my issue which has paths like And thanks for the callout on regex! I will replace that with a proper loop shortly for better performance 🚀 |
I did a hand coding of the method for removing duplicate slashes and a benchmark to compare it to Regex. All work for that has been pushed to this branch. Both seem to perform well and the regex appears to do better in more "real world" examples. Below is a run from my M1 MacBook Pro. Slowest performing scenario seems to be ~150ns / function call or ~500 CPU clock cycles for a 40 character string, which comes to ~10 CPU cycles per character. Also note that "no-op" scenarios where there are no duplicate slashes (which is presumably the majority of paths that would be processed in the real world) appears to only ~3 CPU cycles per character! 😄
|
Hmm, it looks like regex in that case works really faster. Can you provide |
Another issue I'm worried about is that we shouldn't modify a wildcard part of the path. You can see that we return a wildcard param without trimming the last slash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@code-ape Hi, do you need any help? Can you remove non-regexp implementation and provide benchmark results?
687688d
to
6d66fe1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Overview
This is a PR for the feature discussed in #240 which relates to expected behavior for duplicate slashes in path. It was stated this would be a welcome PR and @mcollina directed me to PR #50 for reference of implementing a similar feature.
Related Issues & PRs
Changes
ignoreDuplicateSlashes
which will condense any continuous occurrence of/
in the path into a single/
.ignoreDuplicateSlashes
following pattens of existing tests forignoreTrailingSlash
.README.md
.