Polka: Should I decode URL params myself?

Created on 23 Apr 2020  路  4Comments  路  Source: lukeed/polka

I am running into a problem with this Chrome issue:
https://bugs.chromium.org/p/chromium/issues/detail?id=943026

The thing is that Chrome encodes the pipe character | and Firefox doesn't. So a URL like:

# route: app.get('route/:myParam', ...)
GET https://server.asdf/route/asdf|123456

goes through unencoded (as it should) on Firefox and on Chrome it arrives encoded, breaking the request since myParam has a different value on both browsers.

Now it seems to me that Polka does not decode params coming via the URL itself, only through the query.

My question: Should I add middleware for this myself or is this something that you would include in Polka?

question

All 4 comments

Hi there, what version of Polka are you using?

Hey, thanks for the quick response! I'm using v0.5.2

Ah, then yes. In @next decoding is automatic, and does the whole URL.

If you just want to upgrade a piece of your app, you can by upgrading the parse method to use @polka/url@next

const parser = require('@polka/url');
const polka = require('polka');

const main = polka() // ...;

main.parse = (req) => parser(req, true);

main.listen(...)

Hope that helps!

Great, that's exactly what I need! Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

itaditya picture itaditya  路  3Comments

ansarizafar picture ansarizafar  路  3Comments

lukeed picture lukeed  路  10Comments

lukeed picture lukeed  路  3Comments

galuh1300d picture galuh1300d  路  4Comments