Skip to content
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

Updated to path-to-regexp@3.0.0 #42

Closed
wants to merge 1 commit into from

Conversation

wesleytodd
Copy link
Member

This would probably be a major version bump for router since the path matching semantics are so different.

Also. you will notice a change in the tests. I opened a separate issue to discuss, #41.

@dougwilson
Copy link
Contributor

Also. you will notice a change in the tests. I opened a separate issue to discuss, #41.

The test has been fixed for quite a while on master. I can see this PR cannot even be merged by GitHub, so I think you have it based off some stale code.

@wesleytodd
Copy link
Member Author

Yep, forgot to update my forked version. Will do that now, sorry.

@dougwilson
Copy link
Contributor

And yes, bumping would be 2.0, which is fine :) Can we get a migration guide written up for users to understand how to translate their routes from the old style to the new style to add with this? I think that's really the only blocker.

@wesleytodd
Copy link
Member Author

Based on the tests there is one breaking use case because * is not a valid regexp. This means /:foo(*) needs to become /:foo(.*).

I think @blakeembrey could probably provide a more comprehensive list of changes, but then I would be happy to write them up into a guide.

@blakeembrey
Copy link
Member

I've written the differences a bundle of times, I think the most comprehensive was for Doug in the Express repo.

@dougwilson
Copy link
Contributor

The tests in this module do not actually exercise the different syntaxes currently, so knowing what broke is not possible from this test suite (for example, I don't see you adding any tests for all the new syntax in 1.x, continuing that trend ;) ).

@wesleytodd
Copy link
Member Author

I can add a bunch more tests for the supported syntax if you like. It would seem weird to test features of path-to-regexp in this module though, so I would prefer to keep it the way it is.

For documentation, is what is listed here comprehensive? Can we just do a link here to that section?

@wesleytodd
Copy link
Member Author

I cannot find any more docs that what is in that readme. So I added them here.

As for tests, I think testing dependencies is not a great decision. But I understand the reasoning here because path-to-regexp makes up a HUGE portion of the interface for the router. If we could come up with a way to exercise the tests from the underlying module where when it updated, we automatically were testing the new features, then I think it would be fine. Otherwise it is just a maintenance headache.

Either way, this update does not make us worse off. So IMO it could be merged.

@wesleytodd wesleytodd changed the title Updated to path-to-regexp@1.4.0 Updated to path-to-regexp@1.7.0 Mar 25, 2017
@dougwilson
Copy link
Contributor

I agree that extensively testing dependencies is not great. But sometimes I still think that at least basic tests of the main features of a dependency as they are directly exposed through the interface of this module helps flush out accidental regressions upstream and can help us understand if we can bump a major in that dep without bumping our dep.

@dougwilson
Copy link
Contributor

Thanks for starting on the migration guide :) ! One thing I noticed right away is that the migration guides doesn't provide any guidance on whatever the reason the tests were changed in order to up this dep?

@wesleytodd
Copy link
Member Author

wesleytodd commented Mar 27, 2017

I added tests, I think they should be satisfactory, hits the major points. Let me know if there is anything else you would like me to add.

As for the guide thing, I am really unsure what the core changes were, so I don't actually know what to add. I am happy to add what other people post here, or let them add to this PR as necessary.

@gajus
Copy link

gajus commented Oct 13, 2017

The latest version is 2.0.0.

@dougwilson
Copy link
Contributor

Yea, so we still need a migration guide from the respect of this module. Users need to understand what routes they need to change and how during the upgrade or they'll never be able to upgrade their apps successfully. It seems the 2.0 release breaks even more tha. The 1.0, which is fine, but I'm not even clear on how to upgrade the route paths for the transition.

@blakeembrey
Copy link
Member

Just a note, but compatibility is still listed in https://github.com/pillarjs/path-to-regexp#compatibility-with-express--4x. The primary difference between 1.x and 2.x was that I needed to drop support for * - it wasn't clear how it was meant to be encoded when converting a "path string" like /* into /foo/bar.

@wesleytodd wesleytodd changed the title Updated to path-to-regexp@1.7.0 Updated to path-to-regexp@2.0.0 Oct 13, 2017
@wesleytodd
Copy link
Member Author

Ok, I just updated this PR. But it appears that something also changed with the handling of trailing slashes. @blakeembrey Know what I need to do to fix the two tests I added skip to?

@wesleytodd
Copy link
Member Author

I just updated the upgrade guide as well. Any thoughts or changes necessary?

@dougwilson
Copy link
Contributor

Does this include the changes between 0.1.x and 2.x or just 0.2.x and 2.x? What were the differences between 0.1.x and 0.2.x, again?

@wesleytodd
Copy link
Member Author

AFAIK, this guide is ALL of the changes since 0.1.7.

README.md Outdated
The main change is the update to `path-to-regexp@2.0.0`, which has a few breaking changes:

- No longer a direct conversion to a RegExp with sugar on top - it's a path matcher with named and unnamed matching groups
- It's unlikely you previously abused this feature, it's rare and you could always use a RegExp instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should explain how to know if you are using the feature rather than editorial that "you're probably not using it"

Copy link
Member Author

@wesleytodd wesleytodd Oct 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blakeembrey I copied this from your readme. Can you give me a short blurb to help explain what this means?

Like what is an example "abuse of this feature"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. It's anywhere someone is abusing stuff like /\\d+ outside of a matching group (e.g. instead of /(\\d+)). It's possible it's used in places today, but wouldn't be too useful since it wouldn't result in a match the user could use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you end up coming up with a better or more succinct explanation, happy to replace the one in the README 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd be surprised what people do with these routes. Express 4.16.1 is a release just because it seemed to be popular to do something thag shouldn't work, but did.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: What specifically does this mean?

Parameters have suffixes that augment meaning - *, + and ?. E.g. /:user*

Couldn't we always use those suffixes? How are they different from 0.1.7 to 2.0.0?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, 0.x never had a concept of "suffixes". There's places where it happened to work because everything is treated as a regexp with based search and replace. E.g. /* became /(.*) in search and replace (that's the reason you can't use * in Express.js). It also means that, yes, stuff like /:user? might have worked but purely because of the search and replace implications and definitely not consistently (for instance, /:test* never would have done anything expected).

Note: I haven't tested the specific examples above, but it's possible a comparison (0.x -> 2.x) might be the easiest way to understand the differences.

Copy link
Member Author

@wesleytodd wesleytodd Oct 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that is probably why those worked for me :)

I was actually thinking it might be nice to update the demo app to support multiple versions, which might be helpful for people to discover the differences for their routes. Maybe I can work on that next.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got a PR for that feature in the demo app: ForbesLindesay/express-route-tester#11

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you all need to see the differences in the versions you can view it here until the PR is merged: https://wesleytodd.github.io/express-route-tester/

README.md Outdated
- No longer a direct conversion to a RegExp with sugar on top - it's a path matcher with named and unnamed matching groups
- It's unlikely you previously abused this feature, it's rare and you could always use a RegExp instead
- All matching RegExp special characters can be used in a matching group. E.g. `:user(*)` needs to become `/:user(.*)`
- Other RegExp features are not support - no nested matching groups, non-capturing groups or look aheads
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in "support"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@blakeembrey
Copy link
Member

@wesleytodd See https://github.com/pillarjs/path-to-regexp/blob/master/History.md#300--2019-01-13. Specifically it was the treatment around delimiter tokens (e.g. the character before :token), it was improved to handle a couple of use-cases more elegantly and removed "partial" token support which is actually better handled by escaping characters.

@wesleytodd
Copy link
Member Author

Awesome, so I updated to 3.0, it caused one test failure. I added another section to the readme to describe the change, and made the corresponding test change. This should be good to merge now I think.

@wesleytodd wesleytodd changed the title Updated to path-to-regexp@2.40 Updated to path-to-regexp@3.0.0 May 26, 2019
@wesleytodd
Copy link
Member Author

Too many versions too fast :P

@blakeembrey Should we update this to 5? What are the breaking changes in 4 and 5?

@blakeembrey
Copy link
Member

@wesleytodd See https://github.com/pillarjs/path-to-regexp/releases. 4.0 was for ES2015, 5.0 was because I added a feature(s) I shouldn't have.

@wesleytodd
Copy link
Member Author

Ahh, I was wondering about that quick jump from 3 to 5. There was too many notifications for me to read all of them and follow. Could you summarize the changes so we can add it to the readme and docs? I will update the PR from there.

@blakeembrey
Copy link
Member

blakeembrey commented Nov 20, 2019

@wesleytodd The only mentionable feature is support for nested non-capturing regex groups, e.g. /(abc(?=d)). No breaking changes in these releases for paths, only library usage (e.g. module.exports -> module.exports.pathToRegexp).

Edit: Technically someone could be doing /(abc(def) and expecting it to escape the (, so it's not technically true that there are no breaking changes and only features.

@blakeembrey
Copy link
Member

Final release I intend to make for this library is https://github.com/pillarjs/path-to-regexp/releases/tag/v6.0.0, which reverts some of the confusion I added in v3 and adds an alternative ({}) to support the reason I did the any character prefix in v3.

console.log(req.params) // {'foo': 'bar'}
```

#### Partial matching, prefer escaping delimiter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section shouldn't be relevant anymore. However, you can make the example /user{s}? if you wanted to.

@@ -645,7 +645,7 @@ describe('Router', function () {
it('should work following a partial capture group', function (done) {
var cb = after(2, done)
var router = new Router()
var route = router.route('/user(s)?/:user/:op')
var route = router.route('\\/user(s)?/:user/:op')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good to revert this.

@gireeshpunathil
Copy link

this needs a rebase. anything else?

@dougwilson
Copy link
Contributor

This needs nothing at this time as Wes rebased it on a separate branch instead of within the PR. Github will close it automatically after I move the changes back to the PR branch.

@dougwilson
Copy link
Contributor

So it looks like I don't have permission to push up to the remote branch. This is just a heads-up, so the changes will end up landing on the 2.0 branch, and will end up stating this PR is "closed" instead of "merged".

@gireeshpunathil
Copy link

the changes will end up landing on the 2.0 branch, and will end up stating this PR is "closed" instead of "merged".

@dougwilson - can you clarify what does this mean? the PR is originally destined for 2.0 branch itself, right? or is there a change? or is it that the landing will be same (to 2.0) but the github web interface will show it as closed, while the code would have landed?

@dougwilson
Copy link
Contributor

This PR has merge conflicts that must be resolved, and even has an incomplete section in the migration guide among other changes that are needed. I am working on the changes, but I get permission denied trying to push them up to the PR branch. Since I cannot push them into this PR first, landing this PR + changes onto 2.0 will cause GitHub to mark this PR as "closed" instead of "merged", is all.

dougwilson pushed a commit that referenced this pull request Mar 13, 2020
@dougwilson
Copy link
Contributor

All the changes here + various fix ups has landed into the 2.0 branch 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants