From f3b0c82f4d0ac41d31455b674742a84f5dbf6aae Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Wed, 5 Jan 2022 04:03:26 -0800 Subject: [PATCH] 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 --- xplat/Flipper/FlipperURLSerializer.cpp | 27 ++------------------------ 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/xplat/Flipper/FlipperURLSerializer.cpp b/xplat/Flipper/FlipperURLSerializer.cpp index 0c298723c..99222f8bb 100644 --- a/xplat/Flipper/FlipperURLSerializer.cpp +++ b/xplat/Flipper/FlipperURLSerializer.cpp @@ -35,7 +35,8 @@ std::string URLSerializer::serialize() { if (key == "csr") { query += Base64::encode(value); } else { - query += url_encode(value); + query += + folly::uriEscape(value, folly::UriEscapeMode::QUERY); } append = true; } @@ -43,29 +44,5 @@ std::string URLSerializer::serialize() { 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 facebook