Should pathname patterns automatically match an optional trailing /
?
#38
Replies: 2 comments 4 replies
-
Hey, @wanderview. Thank you for an open opportunity to discuss When it comes to trailing slashes, I believe that developers expect them to be optional. Such expectation comes from the way various libraries and frameworks handle trailing slashes and should be taken into account when designing the I took the liberty of analyzing how some of the major server-side frameworks handle trailing slashes. I haven't found a framework that would be sensitive to trailing slashes. Frameworks I've tested:
AmbiguityThe question itself is rather tricky, as |
Beta Was this translation helpful? Give feedback.
-
We have built a standards-based API Gateway at Zuplo and use For now, we instruct people to follow the spec and modify the regex, but this doesn't seem like a long-term solution for us (it's just not a good developer experience). I would really prefer an option on URL Pattern that allows for non-strict matching that allows optional trailing slash matching. |
Beta Was this translation helpful? Give feedback.
-
By default path-to-regexp operates in a "non-strict" mode. This means that a trailing
/
is always allowed at the end of the input. For example, if the pattern is/foo/bar
it will also match/foo/bar/
automatically.URLPattern currently uses "strict" mode, however. This means that
/foo/bar
does not match/foo/bar/
. This was chosen since it seems important to be able to target input without a trailing slash which is impossible in non-strict mode. In addition, the developer can easily opt-in to the non-strict behavior by appending{/}?
to the end of their pattern. So in our example they would use/foo/bar{/}?
.What do you think?
(Note, this is also discussed in #14, but we would like to collect community feedback in the discussion and then summarize in the issue.)
Beta Was this translation helpful? Give feedback.
All reactions