Skip to content

Commit

Permalink
using httpuv url encode / decode
Browse files Browse the repository at this point in the history
Fix originally proposed by @cliveseldon to use urltools url_decode / url_encode.  Using httpuv to avoid an extra dependency
  • Loading branch information
schloerke committed Dec 7, 2018
1 parent 4f2e73d commit 6293fca
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Expand Up @@ -28,9 +28,9 @@ import(stringi)
importFrom(grDevices,dev.off)
importFrom(grDevices,jpeg)
importFrom(grDevices,png)
importFrom(httpuv,decodeURI)
importFrom(httpuv,encodeURI)
importFrom(httpuv,runServer)
importFrom(stats,runif)
importFrom(utils,URLdecode)
importFrom(utils,URLencode)
importFrom(utils,compareVersion)
importFrom(utils,packageVersion)
4 changes: 2 additions & 2 deletions R/cookie-parser.R
Expand Up @@ -4,7 +4,7 @@ cookieFilter <- function(req){
forward()
}

#' @importFrom utils URLdecode
#' @importFrom httpuv decodeURI
#' @noRd
parseCookies <- function(cookie){
if (is.null(cookie) || nchar(cookie) == 0){
Expand All @@ -25,5 +25,5 @@ parseCookies <- function(cookie){
cookies <- lapply(cookieList, "[[", 2)
names(cookies) <- sapply(cookieList, "[[", 1)

return(lapply(cookies, URLdecode))
return(lapply(cookies, decodeURI))
}
1 change: 0 additions & 1 deletion R/post-body.R
Expand Up @@ -11,7 +11,6 @@ postBodyFilter <- function(req){
forward()
}

#' @importFrom utils URLdecode
#' @noRd
parseBody <- function(body, charset = "UTF-8"){
# The body in a curl call can also include querystring formatted data
Expand Down
5 changes: 2 additions & 3 deletions R/query-string.R
Expand Up @@ -9,7 +9,6 @@ queryStringFilter <- function(req){
forward()
}

#' @importFrom utils URLdecode
#' @noRd
parseQS <- function(qs){
if (is.null(qs) || length(qs) == 0 || qs == "") {
Expand All @@ -24,11 +23,11 @@ parseQS <- function(qs){
kv <- kv[sapply(kv, length) == 2] # Ignore incompletes

keys <- sapply(kv, "[[", 1)
keys <- unname(sapply(keys, URLdecode))
keys <- unname(sapply(keys, decodeURI))

vals <- sapply(kv, "[[", 2)
vals[is.na(vals)] <- ""
vals <- unname(sapply(vals, URLdecode))
vals <- unname(sapply(vals, decodeURI))

ret <- as.list(vals)
names(ret) <- keys
Expand Down
4 changes: 2 additions & 2 deletions R/response.R
Expand Up @@ -41,10 +41,10 @@ PlumberResponse <- R6Class(
)
)

#' @importFrom utils URLencode
#' @importFrom httpuv encodeURI
#' @noRd
cookieToStr <- function(name, value, path, expiration=FALSE, http=FALSE, secure=FALSE){
val <- URLencode(as.character(value))
val <- encodeURI(as.character(value))
str <- paste0(name, "=", val, "; ")

if (!missing(path)){
Expand Down

0 comments on commit 6293fca

Please sign in to comment.