Skip to content

Commit

Permalink
fix oauth_encode() (r-lib#424)
Browse files Browse the repository at this point in the history
* fix oauth_encode()

* update test

* update NEWS
  • Loading branch information
yutannihilation authored and jiwalker-usgs committed Jul 24, 2017
1 parent e63da51 commit bbb423f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
callback functions that are called right before and after performing an
HTTP request (@gaborcsardi #409)

* Fix bug for OAuth 1 process: `oauth_encode()` now handles UTF-8 characters correctly.
(@yutannihilation #424)

# httr 1.2.1

* Fix bug with new cache creation code: need to check that
Expand Down
2 changes: 1 addition & 1 deletion R/oauth-signature.r
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ oauth_encode <- function(x) vapply(x, oauth_encode1, character(1))

# As described in http://tools.ietf.org/html/rfc5849#page-29
oauth_encode1 <- function(x) {
encode <- function(x) paste0("%", toupper(as.character(charToRaw(x))))
encode <- function(x) paste0("%", toupper(as.character(charToRaw(x))), collapse = "")

x <- as.character(x)
chars <- strsplit(x, "")[[1]]
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-oauth.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ test_that("partial OAuth1 flow works", {
expect_equal(status_code(r), 200)
})

test_that("oauth_encode1 works", {
# chinese characters for "xaringan"
orig_string <- "\u5199\u8f6e\u773c"
restored_string <- URLdecode(oauth_encode1(orig_string))
Encoding(restored_string) <- "UTF-8"

expect_equal(orig_string, restored_string)
})

0 comments on commit bbb423f

Please sign in to comment.