-
Notifications
You must be signed in to change notification settings - Fork 299
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
[bug fix] Stop manual URI parsing/escaping and use CGI::parse #119
Conversation
and use URI::HTTP standard library.
85ae3c6
to
cc26e0f
Compare
Hey @smaeda-ks thank you! i'll connect with you and @dlamacchia as I'm not sure what the best approach is to getting this merged. Appreciate it! |
@andypiper @dlamacchia |
|
ping @dlamacchia |
Just found some problems with this PR, will add more commits so please hold on. Thanks |
- URI::decode_www_form can't handle multibyte characters
@dlamacchia OK, so I fixed a bug in the latest commit: 5c05a68 and now I think it's finally safe to merge. cc: @osowskit since you originally gave me an idea of this fix. |
39da09c
to
0e5e5cf
Compare
0e5e5cf
to
14d455a
Compare
- as it doesn't seem to be escaping some of the special characters such as '*' (asterisk). Use CGI.escape instead. - do not parse/escape request POST body in case if "content-type" request header is specified.
14d455a
to
2bcda26
Compare
- follow latest Ruby releases
Problem
Sometimes, users need to pass URL strings that contain query strings as a parameter.
E.g.,
website_url
parameter from the POST accounts/:account_id/cards/website endpoint (Ads API).In this case, they have to escape the URL strings in order to let the parser to parse parameters correctly:
raw:
https://developer.twitter.com/params?aaa=bbb&ccc=ddd
parsed:
https%3A%2F%2Fdeveloper.twitter.com%2Fparams%3Faaa%3Dbbb%26ccc%3Dddd
but the problem is, this code block is doing some extra job and hence the parsed parameter I included in the above twurl request gets "double-escaped".
https://github.com/twitter/twurl/blob/v0.9.3/lib/twurl/cli.rb#L161-L167
so the above twurl request will actually fail like this:
Solution
Just stop doing manual URI parsing and use the
CGI::parse
method instead.Result
As you can see, with this patch,
"website_url": "https://developer.twitter.com/params?aaa=bbb&ccc=ddd",
which is what I expect to see.
Other bug fixes
This PR includes other bug fixes that will resolve the below issues:
#117
#77 (initial PR was: #108)