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

Use decodeURIComponent in recognize method #67

Closed
wants to merge 3 commits into from

Conversation

step2yeung
Copy link

This change would allow matching of URI with encoded characters for ":", "/", ";", and "?". (Since decodeURI does not decode these characters, recognize would not match this.).

Also, this keeps the usage of encodeURIComponent/decodeURIComponent consistent. (This is the only instance of decodeURI used)

@@ -30,6 +30,16 @@ test("A unicode route recognizes", function() {
equal(router.recognize("/uniçø∂∑"), null);
});

test("A unicode with special char route recognizes", function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a unicode test, this is RFC 3986 special cases. Write tests for all of them: *, !:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encodeURIComponent("?#[]@!:$&'()*+,/=;") returns
"%3F%23%5B%5D%40!%3A%24%26'()*%2B%2C%2F%3D%3B"

The characters that gets encoded is: ? # [ ] @ : $ & ' + , / =;
so ! ' ( ) * are characters that does not get encoded.

@rwjblue
Copy link
Collaborator

rwjblue commented Sep 15, 2015

I haven't looked too deeply, but seems like it might be related to or a duplicate of #55.

Can you check?

@step2yeung
Copy link
Author

@rwjblue Not really related, although both PR address the issue encoding and decoding the special cases characters.
#55 address the issue specifically for path segments.
But does not address the situation when we want to match the exact URI which contains encoded special characters ? # [ ] @ : $ & ' + , / =; as part of the URI.


var encoded = "/some/" + encodeURIComponent("reserved?#@:$&+,/=;characters");
resultsMatch(router.recognize(encoded), [{ handler: handler, params: {}, isDynamic: false }]);
equal(router.recognize("/some/eserved?#@:$&+,/=;"), null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the misspelling of reserved intentional? Not sure what this is testing exactly...

@mmun
Copy link
Collaborator

mmun commented Oct 25, 2015

This PR only tests what happens inside of the fragment part of a URL, which the route-recognizer doesn't attempt to deal with.

You should add another assert that doesn't have a # so that query params get tested as well.

> new URL("http://localhost/?@:$&+,/=;characters").search
"?@:$&+,/=;characters"
> new URL("http://localhost/?#@:$&+,/=;characters").hash
"#@:$&+,/=;characters"

@krisselden
Copy link
Collaborator

Superseded by #55 which is fixing all of the encoding issues in a more holistic manner.

@krisselden krisselden closed this Apr 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants