diff --git a/src/engine/hint.cpp b/src/engine/hint.cpp index 9fdb7d168..e24eabd4a 100644 --- a/src/engine/hint.cpp +++ b/src/engine/hint.cpp @@ -4,6 +4,9 @@ #include +#include +#include + namespace osrm { namespace engine @@ -18,13 +21,29 @@ bool Hint::IsValid(const util::Coordinate new_input_coordinates, facade.GetCheckSum() == data_checksum; } -std::string Hint::ToBase64() const { return encodeBase64Bytewise(*this); } +std::string Hint::ToBase64() const +{ + auto base64 = encodeBase64Bytewise(*this); + + // Make safe for usage as GET parameter in URLs + std::replace(begin(base64), end(base64), '+', '-'); + std::replace(begin(base64), end(base64), '/', '_'); + + return base64; +} Hint Hint::FromBase64(const std::string &base64Hint) { BOOST_ASSERT_MSG(base64Hint.size() == ENCODED_HINT_SIZE, "Hint has invalid size"); - return decodeBase64Bytewise(base64Hint); + // We need mutability but don't want to change the API + auto encoded = base64Hint; + + // Reverses above encoding we need for GET parameters in URL + std::replace(begin(encoded), end(encoded), '-', '+'); + std::replace(begin(encoded), end(encoded), '_', '/'); + + return decodeBase64Bytewise(encoded); } } }