Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.15k stars 93 forks source link

Update path2regex (third time's the charm, hopefully.) #171

Closed Lord-Kamina closed 1 year ago

Lord-Kamina commented 1 year ago

I've corrected several errors in my port of the newer javascript code. Behavior should now be identical to path-regexp@6.2.0; and I've updated the test suite to reflect this.

There's still going to be breaking changes for some people, but they'll likely be things path-to-regexp itself already had a while ago. Not all of these have yet made it into express.js, though., given that the 5.0 betas depend on path-to-regexp 3.2.0

From documentation of path-to-regexp, main changes are (most are copied from the path-to-regexp release notes):

This time around, I tested it using C++14, and all tests were passing.

  1. Allow empty string with ending: false to match both relative and absolute paths
  2. Use delimiter when processing repeated matching groups (e.g. foo/bar has no prefix, but has a delimiter)
  3. Support starting option to disable anchoring from beginning of the string
  4. Various enhancements from path-to-regexp 6.0, which are intended partly to restore some compatibility with older versions:
    • Support for nested non-capturing groups in regexp, e.g. /(abc(?=d))
    • Support for custom prefix and suffix groups using /{abc(.*)def}
    • Tokens in an unexpected position will throw an error:
      • Paths like /test(foo previously worked treating ( as a literal character, now it expects ( to be closed and is treated as a group
      • You can escape the character for the previous behavior, e.g. /test\(foo
  5. Support custom prefixes (same as delimiters in RESTinio) option (default is /. which acts like every version since 0.x again)
  6. Add support for {} to capture prefix/suffix explicitly, enables custom use-cases like /:attr1{-:attr2}?
  7. Use /#? as default (end)delimiter to avoid matching on query or fragment parameters; if you are matching non-paths (e.g. hostnames), you can set delimiterto .
  8. Fix invalid matching of :name* parameter

I've updated the test suite to reflect the changes, as well as added some new tests that had been added to the upstream path-to-regexp as well.