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

fix oauth_encode() #424

Merged
merged 4 commits into from
Jul 24, 2017
Merged

fix oauth_encode() #424

merged 4 commits into from
Jul 24, 2017

Conversation

yutannihilation
Copy link
Contributor

This PR fixes #423.

The problem is in this part of oauth_encode1():

 encode <- function(x) paste0("%", toupper(as.character(charToRaw(x))))

This seems to expect the result of charToRaw(x) is a single character, but this assumption fails when x is a UTF-8 character:

paste0(charToRaw(""))
[1] "82" "a0"

Therefore, the following line doesn't work well:

 chars[!ok] <- unlist(lapply(chars[!ok], encode))

As the length of the left hand side is smaller than the right hand side, some bytes at the tail is lost when assigning. That's what this warning says.

httr:::oauth_encode1("写輪眼")
#> [1] "写\x97"
#> Warning message:
#> In chars[!ok] <- unlist(lapply(chars[!ok], encode)) :
#>   number of items to replace is not a multiple of replacement length

This pull request adds collapse = "" so that encode() returns a single character vector.

@Crackz
Copy link

Crackz commented Apr 13, 2017

@yutannihilation Thanks alot 🥇 you saved me

@yutannihilation
Copy link
Contributor Author

@Crackz Oh, I'm glad to hear that 😄 Actually, I've noticed this bug when I was trying rtweet...

@yutannihilation
Copy link
Contributor Author

But, I'm a bit afraid httr may be no more maintained since I see no responses to the issues and PRs since half a years ago. Hmm...

@yutannihilation
Copy link
Contributor Author

yutannihilation commented Apr 13, 2017

Ah, I got it. Hadley says this five months ago:

I'm planning for httr2 in the next six months
#408 (comment)

@Crackz
Copy link

Crackz commented Apr 13, 2017

I hope it come soon ...
but he should pull requests at least
i don't want to live with my customized one

@yutannihilation
Copy link
Contributor Author

Agreed.

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

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

Can you please also add a bullet to NEWS?

restored_string <- URLdecode(oauth_encode1(orig_string))
Encoding(restored_string) <- "UTF-8"

expect_equal(
Copy link
Member

Choose a reason for hiding this comment

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

Can you please put this on one line?

@yutannihilation
Copy link
Contributor Author

Thanks! Updated NEWS and test.

@hadley
Copy link
Member

hadley commented Jul 24, 2017

Thanks!

@yutannihilation yutannihilation deleted the fix-encode branch July 24, 2017 14:03
@yutannihilation
Copy link
Contributor Author

Thanks for merging! This bug was a bit annoying, so I'm very happy to see this closed! 🍺

jiwalker-usgs pushed a commit to jiwalker-usgs/httr that referenced this pull request Jul 24, 2017
* fix oauth_encode()

* update test

* update NEWS
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.

Token1.0 cannot generate proper oauth_signature params for UTF-8 characters
3 participants