Remove custom url_encode in favour of folly uri encode

Summary:
^
There was an issue for some characters in newer android API versions. One option was to fix our implementation, which can be done by casting to char to unsigned int before using std::isalnum.

But, do not duplicate existing functionality, used a solid implementation instead.

Changelog: Fixes an issue whereas the url encoding was incorrect for UTF-8

Reviewed By: mweststrate

Differential Revision: D33405760

fbshipit-source-id: e1c0a4da3dceb27e923b26d0ebfac091febeceb3
This commit is contained in:
Lorenzo Blasa
2022-01-05 04:03:26 -08:00
committed by Facebook GitHub Bot
parent e4184d8b38
commit f3b0c82f4d

View File

@@ -35,7 +35,8 @@ std::string URLSerializer::serialize() {
if (key == "csr") { if (key == "csr") {
query += Base64::encode(value); query += Base64::encode(value);
} else { } else {
query += url_encode(value); query +=
folly::uriEscape<std::string>(value, folly::UriEscapeMode::QUERY);
} }
append = true; append = true;
} }
@@ -43,29 +44,5 @@ std::string URLSerializer::serialize() {
return query; return query;
} }
std::string URLSerializer::url_encode(const std::string& value) {
std::ostringstream escaped;
escaped.fill('0');
escaped << std::hex;
for (std::string::const_iterator i = value.begin(), n = value.end(); i != n;
++i) {
std::string::value_type c = (*i);
// Keep alphanumeric and other accepted characters intact
if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
escaped << c;
continue;
}
// Any other characters are percent-encoded
escaped << std::uppercase;
escaped << '%' << std::setw(2) << int((unsigned char)c);
escaped << std::nouppercase;
}
return escaped.str();
}
} // namespace flipper } // namespace flipper
} // namespace facebook } // namespace facebook