-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
Fix handling of optionals in the middle #173
Conversation
Thanks so much for this library! It’s come in very handy in Shields. We’ve significantly reduced the duplication in our route definitions, and we’re getting really close letting developers build badge URLs in the frontend. We’re running into an issue when an optional token precedes the extension. Many of the routes look something like this: `/travis/:user/:repo/:branch?.ext(svg|png)` - That pattern matches `/travis/foo/bar/master.svg` as we’d expect - Unexpectedly it _does not_ match `/travis/foo/bar.svg` - Unexpectedly it _does_ match `/travis/foo/bar/.svg` I traced the behavior back to pillarjs#71 where it was introduced. I _think_ it was unintentional since that PR was about making the leading delimiter optional for an optional token. I don’t see why the delimiter should be present before an optional in the middle. It’s kind of an odd fix, though it makes some sense given pillarjs#71 was about fixing leading optionals. @RedSparr0w was asking about paths like `/:optional?/:required.json` so I added another test example to the test for that.
1d466db
to
fd29ee3
Compare
@paulmelnikow If this is the wanted behavior, I'm actually leaning toward I'm going to do a follow up PR based on this to explore, hope that's ok 😄 |
Hi!
Go for it 👍 I see why dropping
A workaround might be fine, though I'm not sure I understand what you're suggesting. Could you clarify? |
I'm sorry, I'm terrible at explaining this when it's all going through my head and all theoretical. I meant that if we remove I'm playing around with it to test, the only odd thing in the tests is |
Feel free to take a look #176 for an example. |
Shields may be an edge case, though I can say that we're adapting long established regex-based URL patterns to the library. So in that sense it's not contrived: these are the URLs we need to continue to support, at least for the moment. Here's an example with
Path I would like to match:
Added: As I digest #176 and think about this more, perhaps this is the correct pattern:
|
I'll mention that from perspective of working with this in Shields, escaping the backslash before a leading optional but not before a leading required seems less convenient or intuitive, compared to never escaping it as in this PR. We assemble the pattern by concatenating these:
Put another way: a route needs to specify The reason we make a division between In a couple others, the I hope I'm sharing this in a way that's helpful. Again this is not in my head as much as it's in yours and my perspective is from 10,000 feet away. |
@paulmelnikow Thanks! I think it makes sense. I mostly don't want to mess with |
If you'd like, I'd be happy to try to integrate Shields with the code from #176 to see if the cases we want to support are working. |
@paulmelnikow Sure, that'd actually be helpful. The biggest concern I have is that I removed |
Thanks so much for this library! It’s come in very handy in Shields. We’ve significantly reduced the duplication in our route definitions, and we’re getting really close letting developers build badge URLs in the frontend.
We’re running into an issue when an optional token precedes the extension. Many of the routes look something like this:
/travis/:user/:repo/:branch?.ext(svg|png)
/travis/foo/bar/master.svg
as we’d expect/travis/foo/bar.svg
/travis/foo/bar/.svg
I traced the behavior back to #71 where it was introduced. I think it was unintentional since that PR was about making the leading delimiter optional for an optional token. I don’t see why the delimiter should be present before an optional in the middle.
It’s kind of an odd fix, though it makes some sense given #71 was about fixing leading optionals.