I need to decode with R strings that are URL encoded using RFC 1738.
These strings are coming from PHP requests and encoded with the PHP function http_build_query
which uses RFC1738 by default.
For example, Hello, World!
becomes Hello%2C+world%21
.
You can easily try it online with the following PHP code:
$data = array(
'text' => 'Hello, world!'
);
echo http_build_query($data, '', '&');
Unfortunately, R base URL encoding uses RFC 3986, which is different!
utils::URLdecode("Hello%2C+world%21")
# "Hello,+world!"
# I was hoping httpuv would have an option for RFC 1738 but it doesn't!
httpuv::decodeURIComponent("Hello%2C+world%21")
# "Hello,+world!"
I want to get "Hello, world!"
back! How can I do that with R?
I am happy to just replace
+
signs with spaces but, if this is your answer, please justify why this is correct. My research so far did not indicate that RFC 1738 is exactly RFC 3986 with plus signs and I don't want weird edge cases...