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

break: do not decode req.path by default #172

Merged
merged 4 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/polka/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ class Polka extends Router {
}

handler(req, res, next) {
let info = this.parse(req, true);
let info = this.parse(req);
let obj = this.find(req.method, req.path=info.pathname);

req.params = obj.params;
req.params = {};
Object.entries(obj.params).forEach(([key, val]) => (req.params[key] = decodeURIComponent(val)));
benmccann marked this conversation as resolved.
Show resolved Hide resolved
req.originalUrl = req.originalUrl || req.url;
req.url = info.pathname + info.search;
req.query = info.query || {};
Expand Down
8 changes: 4 additions & 4 deletions packages/polka/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1425,16 +1425,16 @@ test('HEAD', async () => {
});


test('decode url', async () => {
test('encoded url', async () => {
// t.plan(8);

let sub = (
polka()
.get('/:foo', (req, res) => {
assert.ok('~> inside "GET /sub/:foo" handler')
assert.ok(req._decoded, '~> marked as decoded');
assert.is(req.path, '/føøß∂r', '~> decoded "path" value');
assert.is(req.url, '/føøß∂r?phone=%2b8675309', '~> decoded "url" value partially');
assert.ok(!req._decoded, '~> not marked as decoded');
assert.is(req.path, '/f%C3%B8%C3%B8%C3%9F%E2%88%82r', '~> "path" value');
assert.is(req.url, '/f%C3%B8%C3%B8%C3%9F%E2%88%82r?phone=%2b8675309', '~> "url" value');
assert.is(req.params.foo, 'føøß∂r', '~> decoded "params.foo" segment');
assert.is(req.query.phone, '+8675309', '~~> does NOT decode "req.query" keys twice');
res.end('done');
Expand Down