visionmedia / page.js

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

Query string decoding #216

Open markkemper1 opened 9 years ago

markkemper1 commented 9 years ago

The querystring is url decoded (in the same way as the path). However if the querystring has encoded '=' and '&' characters then you can't parse key / value pairs out of the result.

EXAMPLE: http://test.com/?returnurl=http%3A%2F%2Fwww.test.com%3Fabc%3D1%26def%3D2&abc=3 ctx.querystring = "returnurl=http://www.test.com?abc=1&def=2&abc=3"

So the decoded '&' and '=' above causes issues. I can't think of the reason why the querystring is being decoded. At the very least there should be a separate option to turn the querystring decoding on/off (separate to the existing option)

Unless I'm missing something?

Mr0grog commented 9 years ago

I'd really love to see this fixed as well. Just tripped over it while using this plugin on a somewhat sizable project, and now my codebase has code to parse context.path for the querystring :\

Limess commented 9 years ago

I'd like to see this fixed, can easily see it tripping me up in the near future.

A commented 9 years ago

@woodlandhunter can you take a look, please?

woodlandhunter commented 9 years ago

Sure, I'll take a look this week.

TheMoonDawg commented 7 years ago

Also encountering this as well. I guess it hasn't been fixed over a year later. Looks like I'll have to parse through context.path as well for the time being.

woodlandhunter commented 7 years ago

I forgot about this, I'll confess. Maybe @hheiskanen can comment on the various changes to url decoding as there wasn't much discussion about why except on #187 which is about adding the option to disable all decoding.

173

189

194

TheMoonDawg commented 7 years ago

It was an easy enough work around using context.path (which didn't automatically decode it). Here's the simple parsing code I wrote in case it helps anyone else for the time being! It just extracts out the query string portion of the URL (if it exists).

        var qs = context.path;
        var index;

        for (x = 0; x < qs.length - 1; x++) {
            if (qs[x] === '?' && (x + 1 < qs.length)) {
                index = x + 1;
                break;
            }
        }

        if (index) qs = qs.substring(index);
hheiskanen commented 7 years ago

@MoonDawg92, did you try setting decodeURLComponents to false in the config object that can be passed to page.start? By default it is true (as documented in the readme) and will cause page.js to decode the query string, pathname and hash in the Context object.

This config option was added as a convenience for working with those URL segments, without the user having to manually decode them every time when extracting the values. In cases where to query string contains a URL the default decoding behavior should be turned off in the config object.

TheMoonDawg commented 7 years ago

@hheiskanen You know, I guess I must have just completely glossed over that.

Just turned the decodeURLComponents flag to false in our start up script, and it worked like a charm. Thanks for the help!