Closed antoine-sachet closed 5 years ago
From my reading of RFC 1738, it doesn't say that spaces should be encoded as +
.
I believe that +
means space when the mime type is application/x-www-form-urlencoded
. See here: https://stackoverflow.com/a/2678602/412655
The intent of encode/decodeURIComponent
is that they behave like their JavaScript counterparts, so we're unlikely to add this functionality. Can you just wrap it in your own function that replaces +
with
?
You're right, I had misunderstood the PHP documentation, the plus signs are because of the mime type, not RFC1738.
If enc_type is PHP_QUERY_RFC1738, then encoding is performed per » RFC 1738 and the application/x-www-form-urlencoded media type, which implies that spaces are encoded as plus (+) signs.
Re your suggestion, this is exactly what I am doing.
url_decode <- function(str) {
str <- gsub(str, pattern = "+", replacement = "%20", fixed = TRUE)
httpuv::decodeURIComponent(str)
}
Thanks
Sometimes, I need to interface with servers working with RFC 1738 URL encoded strings (PHP outdated default for
http_build_query
) instead of the more recent RFC 3986. The main difference is that spaces are encoded as+
instead of%20
.More context on StackOverflow.
It would be quite amazing if
encode/decodeURI
andencode/decodeURIComponent
could take an optional argumentencoding
which would be"rfc3986"
by default but could be set to"rfc1738"
.Similar to the
enc_type
argument of the PHP functionhttp_build_query
.