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

Implement rfc3986 option #1315

Merged
merged 5 commits into from Dec 23, 2014
Merged

Implement rfc3986 option #1315

merged 5 commits into from Dec 23, 2014

Conversation

simov
Copy link
Member

@simov simov commented Dec 13, 2014

Fixes #578
Fixes #1287

My first try on the rfc3986 issue, @mikeal @nylen @olado let me know what do you think

@simov
Copy link
Member Author

simov commented Dec 15, 2014

I just enabled the last test simov@e24762f since #1314 got in.

@nylen
Copy link
Member

nylen commented Dec 15, 2014

Is there a reason why we wouldn't want this to be the default behavior (would that break things)?

Best way to document this? Probably mention it in the OAuth example.

@simov
Copy link
Member Author

simov commented Dec 15, 2014

As quoted in this #1287 (comment) there wouldn't be any problems, currently all parameters in the authorization header are being rfc3986 encoded (in the OAuth method).

I opted out for an option due to the breaking changes introduced by some of the new features lately (and because it's used only for Twitter)

As for the end users, they can set this option through the defaults method to use with each request to Twitter.

If it's going to be an option it should be documented under the options section.

@simov
Copy link
Member Author

simov commented Dec 16, 2014

@nylen I think enabling this by default should be fine, I just made some tests on my own, plus the implementation would be a bit cleaner without all of these conditional statements.

@nylen
Copy link
Member

nylen commented Dec 16, 2014

It only matters for *, but according to https://tools.ietf.org/html/rfc5849#page-29 the hex encoding should be upper case:

 function rfc3986 (str) {
   return str.replace(/[!'()*]/g, function(c) {
-    return '%' + c.charCodeAt(0).toString(16)
+    return '%' + c.charCodeAt(0).toString(16).toUpperCase()
   })
 } 

@simov
Copy link
Member Author

simov commented Dec 16, 2014

Ok, I saw the upper case bits, what about the * symbol ? Also what is your opinion on enabling this encoding by default?

@nylen
Copy link
Member

nylen commented Dec 16, 2014

Same issue (the only character in !'()* that has a letter in its hex representation is *).

I'm for enabling this by default, unless someone can tell me that it would break things. What have you done to test it so far?

@simov
Copy link
Member Author

simov commented Dec 16, 2014

Ok, I can remove the option and just wrap all places where it's used with the rfc3986 encoding method.

The unit tests are here basically testing with a bunch of options combinations. There a few more I think, but at the time I was writing it, I though they are not so important.

I ran my system tests in purest with the code from this PR. I added the !'()* symbols in the post tests, just a couple of providers there, and checked the output on their web interfaces, I was curious if the symbols are printed correctly. Also a few email APIs there all seems to work without a problem, I haven't tested with multipart though.

EDIT: scratch the multipart bits 😁

@nylen
Copy link
Member

nylen commented Dec 16, 2014

👍 I think after that we are good to merge.

Since it's the correct behavior according to a couple of RFCs, I don't think we need docs for this. And any decoding implementation shouldn't care which characters are encoded, so I don't see how it will break anything.

A confirmation that this fixes the original issue with Twitter would be nice also? Ping @olado

@olado
Copy link

olado commented Dec 16, 2014

Thank you for looking into this issue @simov @nylen . I can't test it at the moment, will try in the evening.

@simov
Copy link
Member Author

simov commented Dec 16, 2014

Pushed, made it by default. A confirmation from @olado would be great idd.

Btw, @nylen I have tests for Twitter, my point with my previous comment was that I tested with a bunch of other REST API providers as well. In fact I use the exact same function in my module from about an year ago, but I have an option in my layer to override the request options per provider if needed. So currently I'm using it only for Twitter, my concerns were with the rest of the providers, not Twitter.

@simov
Copy link
Member Author

simov commented Dec 17, 2014

Doh, forgot to add the upper case bits yesterday.

@nylen
Copy link
Member

nylen commented Dec 23, 2014

Ping @olado re Twitter test. Going ahead and merging though, thanks @simov.

nylen added a commit that referenced this pull request Dec 23, 2014
Implement rfc3986 option
@nylen nylen merged commit 37fbff4 into request:master Dec 23, 2014
simov added a commit to simov/request that referenced this pull request Feb 2, 2015
Example {json:{}} or {body:{}, json:true}
Related to request#1315
Closes request#1395
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.

Issue with posting exclamation marks to twitter
3 participants