koajs / router

Router middleware for Koa. Maintained by @forwardemail and @ladjs.
MIT License
853 stars 181 forks source link

[RFC] URL-encode path parameters for Router.url #116

Closed ide closed 2 years ago

ide commented 3 years ago

This is a proposal for a public API change.

The main breaking change from v8.x to v9.x was an upgrade to path-to-regex. That PR alluded to a breaking change in encoding. Namely, parameters were not URL-encoded: parameters with safe special characters (like spaces) were not percent-encoded, and parameters with special characters that mean something in a URL, such as slashes (path separators) and question marks (query string delimiter).

The motivation for this PR is to make URL-encoding be the default since typically the parameters provided to Router.url are plain, unencoded values. Should someone need an escape hatch, they could pass in { encode: null } (I think) to disable the automatic encoding.

This addition to the changelog shows the change by example:

Updated tests, docs, and the changelog.

ide commented 2 years ago

@titanism would you be interested in taking a look at this change? In summary, it fixes query parameter escaping for Router.url.

titanism commented 2 years ago

@koa/router v12.0.0 released to npm, thanks @ide

https://github.com/koajs/router/releases/tag/v12.0.0

mirrored to koa-router