visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.68k stars 688 forks source link

Replacing + (plus) breaks parameters #422

Closed senica closed 7 years ago

senica commented 7 years ago

In the query.js file https://github.com/visionmedia/page.js/blob/master/examples/query-string/query.js

On line 110 (currently) you are replacing the '+' sign

pair = decodeURIComponent(pair.replace(/\+/g, ' '));

But this breaks values with a plus sign in it.

For example:

page('*', (ctx, next)=>{
  console.log('query', ctx.querystring) // << already decoded
  ctx.query = qs.parse(ctx.querystring);
  console.log('query after', ctx.query) // << removes + sign...why?
  next();
})

If I have a route like page('/user?email=senica%2B3%40gmail.com') which is encodeURIComponent(senica+3@gmail.com), then the first line above will show the query string as email=senica+3@gmail.com but after it goes into qs.parse, it comes out as senica 3@gmail.com. Notice the space where the plus sign is replaced.

Is there a reason for this happening?

senica commented 7 years ago

Ah, I realized it was actually wanting a non-decoded url. Sorry.