GoogleChromeLabs / sw-toolbox

[Deprecated] A collection of service worker tools for offlining runtime requests
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
3.62k stars 331 forks source link

decode URI params #212

Closed jimmywarting closed 7 years ago

jimmywarting commented 7 years ago

I had something with space included

/api/books/:book/:page

Was going to make a query agains the book but got no match since value.book include %20 (space) so i had to decodeURI. Something i think can be done automatically by sw-toolbox

jeffposnick commented 7 years ago

Could you provide more insight as to what the actual, live URL paths look like on your site and the specific routing configuration you're using with sw-toolbox?

I have a feeling that the RegExp-based routing should be able to handle this without much of an issue, but I'm not surprised if the Express-style routing has trouble.

jimmywarting commented 7 years ago
router.get('/tv/:channel', ({channel}){
  console.log(channel) // ABC%20news
  channel = decodeURI(channel) // ABC News
})

and the url: localhost:8080/tv/ABC news/

jeffposnick commented 7 years ago

Thanks, now I understand what you mean.

At this point, I don't feel comfortable changing the way sw-toolbox passes named parameters to the route callback, given the potential for surprising folks who were relying on the old behavior, and because this is the first time it's been requested by a developer.

Explicitly handling URL decoding within your own code (or explicitly URL encoding strings that you're going to match against the named parameters), if you work with URLs that contain characters which require it, is the best approach given the situation.