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

feat: upgrade path-to-regexp #216

Merged
merged 1 commit into from
Nov 26, 2023
Merged

feat: upgrade path-to-regexp #216

merged 1 commit into from
Nov 26, 2023

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Nov 25, 2023

This upgrades path-to-regexp to the latest version.

The behaviour has changed quite a lot since the previous version we were using. Some examples of what has changed:

  • Wildcards are now subpatterns, e.g. /foo/(.*) rather than /foo/*
  • Delimeters are parsed everywhere (http://foo would think ://foo or something is a parameter)
  • Characters need escaping, e.g. foo?bar must be foo\\?bar since you can now have optional parameters like /foo/:bar?

To account for this in the most backwards compatible way possible, this change does the following:

  • Detects :// in URLs and escapes it to \\://
  • Detects /* in URLs and converts it to /(.*)
  • Breaks URLs with unescaped query strings (i.e. foo?bar will no longer behave the same. you must escape, foo\\?bar

The breaking change with query strings is because we can't really reliably replace ? automatically with \\?, since consumers may legitimately want to use the new optional parameters functionality.

Notes/questions

  • We could go all in on a breaking change here and just align with path-to-regexp, i.e. do no detection of backwards compat stuff, just tell consumers to use (.*) and escape : from now on. Thoughts?

This upgrades path-to-regexp to the latest version.

The behaviour has changed quite a lot since the previous version we were
using. Some examples of what has changed:

- Wildcards are now subpatterns, e.g. `/foo/(.*)` rather than `/foo/*`
- Delimeters are parsed everywhere (`http://foo` would think `://foo` or
something is a parameter)
- Characters need escaping, e.g. `foo?bar` must be `foo\\?bar` since you
can now have optional parameters like `/foo/:bar?`

To account for this in the most backwards compatible way possible, this
change does the following:

- Detects `://` in URLs and escapes it to `\\://`
- Detects `/*` in URLs and converts it to `/(.*)`
- **Breaks URLs with unescaped query strings** (i.e. `foo?bar` will no
longer behave the same. you _must_ escape, `foo\\?bar`

The breaking change with query strings is because we can't really
reliably replace `?` automatically with `\\?`, since consumers may
legitimately want to use the new optional parameters functionality.
@fatso83 fatso83 merged commit b800ff1 into sinonjs:main Nov 26, 2023
@fatso83
Copy link
Contributor

fatso83 commented Nov 26, 2023

Thanks for taking the time!

@fatso83
Copy link
Contributor

fatso83 commented May 10, 2024

When reading this in hindsight, it seems I totally glossed over the breaking changes bits of this PR when it was merged, as I would otherwise have made sure to release a new major version, both Nise 6 and Sinon 18, when this was merged. I must have been in a hurry 🙈

This requires updates to the documentation of both Sinon and Nise, as well.

It's a bit late to revert, so we could add a config flag to 17 do the automatic conversion to the old format for query parameters?

@fatso83
Copy link
Contributor

fatso83 commented May 10, 2024

cc @mroderick

@43081j
Copy link
Contributor Author

43081j commented May 11, 2024

no worries, my fault for not spotting that

im guessing the escaping of ? is what has tripped people up? the rest should've already been accounted for

we could basically say:

  • if you're on the old behaviour, we auto-escape all ? and you just can't have optional params
  • if you're on the new behaviour, its up to you to escape ?

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

Successfully merging this pull request may close these issues.

2 participants