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
improve express regex middleware path parsing #3203
Conversation
Overall package sizeSelf size: 4.24 MB Dependency sizes
🤖 This report was automatically generated by heaviest-objects-in-the-universe |
Looks like this code might not be compatible with Express v4:
|
Codecov Report
@@ Coverage Diff @@
## master #3203 +/- ##
==========================================
- Coverage 85.86% 85.82% -0.05%
==========================================
Files 182 182
Lines 7223 7223
Branches 33 33
==========================================
- Hits 6202 6199 -3
- Misses 1021 1024 +3 see 2 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Looks like Express v4.0 broke backwards compat with the router and didn't fix it until 4.6. I'll modify the tests to avoid it. |
a681bd1
to
2643dd3
Compare
2643dd3
to
ffa81c7
Compare
function routeIsRegex (route) { | ||
// console.log('ROUTE', typeof route, route) | ||
// return route instanceof RegExp | ||
return route.includes('(/') && route.includes('/)') |
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.
@rochdev I replaced the .startsWith
and .endsWith
with .includes
. You were right that having a parent router with a path and a child handler being regex was sneaking through.
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.
I think for now this could be sufficient, although I wonder if maybe checking just endsWith
would be enough? Then it would only match if the last nested route was a regex. Not sure whether that's actually better though 🤔
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.
Interesting... What if a parent route is a regex and a child is a path?
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.
I do agree that a single .endsWith
would be a lot faster than two or even one .includes
.
ffa81c7
to
bc874d8
Compare
function routeIsRegex (route) { | ||
// console.log('ROUTE', typeof route, route) | ||
// return route instanceof RegExp | ||
return route.includes('(/') && route.includes('/)') |
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.
I think for now this could be sufficient, although I wonder if maybe checking just endsWith
would be enough? Then it would only match if the last nested route was a regex. Not sure whether that's actually better though 🤔
bc874d8
to
9e49b06
Compare
Co-authored-by: Dominik Krejcik <dominik.krejcik@gmail.com>
Co-authored-by: Dominik Krejcik <dominik.krejcik@gmail.com>
Co-authored-by: Dominik Krejcik <dominik.krejcik@gmail.com>
Co-authored-by: Dominik Krejcik <dominik.krejcik@gmail.com>
Co-authored-by: Dominik Krejcik <dominik.krejcik@gmail.com>
Co-authored-by: Dominik Krejcik <dominik.krejcik@gmail.com>
Co-authored-by: Dominik Krejcik <dominik.krejcik@gmail.com>
What does this PR do?
Motivation