#include "utils/logging.h"
#include "utils/macros.h"
+#include "utils/string_util.h"
namespace {
const char kExpectedXmlns[] = "http://www.w3.org/2000/09/xmldsig#";
return "";
}
-std::string DecodeProcent(const std::string& path) {
- std::vector<int> input(path.begin(), path.end());
- std::vector<char> output;
- int i = 0;
- while (i < input.size()) {
- if ('%' == input[i]) {
- if (i + 2 >= input.size())
- return std::string();
- char str[3] = {"\0",};
- str[0] = input[i + 1];
- str[1] = input[i + 2];
- int result = strtol(str, NULL, 16);
- // RFC 1738 - octets 80 to FF are not allowed
- if (result >= 128)
- return std::string();
- output.push_back(static_cast<char>(result));
- i += 3;
- } else {
- output.push_back(static_cast<char>(input[i]));
- ++i;
- }
- }
- return std::string(output.begin(), output.end());
-}
-
} // namespace
namespace common_installer {
LOG(ERROR) << "Missing URI attribute.";
return false;
}
- std::string decoded_uri = DecodeProcent(uri);
+ std::string decoded_uri =
+ common_installer::utils::DecodePercentEscapedCharacter(uri);
if (!decoded_uri.empty()) {
uri = decoded_uri;
} else {
#include "utils/string_util.h"
+#include <cstdlib>
#include <string>
+#include <vector>
namespace {
return text;
}
+std::string DecodePercentEscapedCharacter(const std::string& path) {
+ std::vector<int> input(path.begin(), path.end());
+ std::vector<char> output;
+ unsigned i = 0;
+ while (i < input.size()) {
+ if ('%' == input[i]) {
+ if (i + 2 >= input.size())
+ return std::string();
+ char str[3] = {"\0",};
+ str[0] = input[i + 1];
+ str[1] = input[i + 2];
+ int result = strtol(str, NULL, 16);
+ // RFC 1738 - octets 80 to FF are not allowed
+ if (result >= 128)
+ return std::string();
+ output.push_back(static_cast<char>(result));
+ i += 3;
+ } else {
+ output.push_back(static_cast<char>(input[i]));
+ ++i;
+ }
+ }
+ return std::string(output.begin(), output.end());
+}
+
} // namespace utils
} // namespace common_installer
std::string StripWrappingBidiControlCharactersUTF8(const std::string& text);
std::string GetDirTextUTF8(const std::string& text, const std::string& dir);
+std::string DecodePercentEscapedCharacter(const std::string& path);
+
} // namespace utils
} // namespace common_installer
if (url_path.empty() || url_path[0] != '/')
return bf::path();
- // TODO(jizydorczyk):
- // We need to unescappe %-encoded UTF8 chars here
- // for now its left undone
- // Drop the leading slashes and convert %-encoded UTF8 to regular UTF8.
-// std::string file_path = net::UnescapeURLComponent(url_path,
-// net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
-// size_t skip = file_path.find_first_not_of("/\\");
-// if (skip != file_path.npos)
-// file_path = file_path.substr(skip);
-
- std::string file_path = url_path;
+ std::string file_path =
+ common_installer::utils::DecodePercentEscapedCharacter(url_path);
+ if (file_path.empty())
+ return bf::path();
+
bf::path path(file_path);
// It's still possible for someone to construct an annoying URL whose path