Explicit prefix and suffix modifiers #306
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Demo using explicit
{}
for prefix/suffix instead of implicit/
and.
, and nothing in other positions. This would allow for much clearer error and edge case handling of things like-:path*
which is meaningless today, while/:path*
is actually useful. It more closely aligns behavior with some other path matching libraries, such as Rails which uses()
to denotes optional.However, it does break compatibility as a result of fixing these quirks. As part of this PR there is a good attempt at ensuring the upgrade path is pretty easy, and it gives clear errors with a link and the exact part of the string where the error occurred. Mostly it'll be
/:path?
to{/:path}?
. I've also disallowed/:path*
which could be confused as*
is now a wildcard, and writing that path is probably a bug. As a result, this does give a simple library upgrade path that adds back/:path?
,/:path+
,/:path*
if needed by users.It's also fairly easy to write a path rewrite script that'll update the syntax if people want it, both for Express.js 4.x and the current major release.