diff --git a/include/exiv2/futils.hpp b/include/exiv2/futils.hpp index 5fa937c9..25b1f38a 100644 --- a/include/exiv2/futils.hpp +++ b/include/exiv2/futils.hpp @@ -69,6 +69,7 @@ namespace Exiv2 @param str The url needs encoding. @return the url-encoded version of str. @note Source: http://www.geekhideout.com/urlcode.shtml + @todo This function can probably be hidden into the implementation details */ EXIV2API std::string urlencode(const char* str); @@ -79,11 +80,13 @@ namespace Exiv2 @note Be sure to free() the returned string after use Source: http://www.geekhideout.com/urlcode.shtml + @todo This function can probably be hidden into the implementation details */ EXIV2API char* urldecode(const char* str); /*! @brief Like urlencode(char* str) but accept the input url in the std::string and modify it. + @todo This function can probably be hidden into the implementation details */ EXIV2API void urldecode(std::string& str); diff --git a/unitTests/test_futils.cpp b/unitTests/test_futils.cpp index 3df6d751..35747b0c 100644 --- a/unitTests/test_futils.cpp +++ b/unitTests/test_futils.cpp @@ -83,3 +83,26 @@ TEST(urlencode, encodesGivenUrl) const std::string url = urlencode("http://www.geekhideout.com/urlcode.shtml"); ASSERT_STREQ("http%3a%2f%2fwww.geekhideout.com%2furlcode.shtml", url.c_str()); } + +TEST(urlencode, encodesGivenUrlWithSpace) +{ + const std::string url = urlencode("http://www.geekhideout.com/url code.shtml"); + ASSERT_STREQ("http%3a%2f%2fwww.geekhideout.com%2furl+code.shtml", url.c_str()); +} + +TEST(urldecode, decodesGivenUrl) +{ + const std::string expectedDecodedUrl ("http://www.geekhideout.com/urlcode.shtml"); + const std::string url ("http%3a%2f%2fwww.geekhideout.com%2furlcode.shtml"); + char * url3 = urldecode(url.c_str()); + ASSERT_STREQ(expectedDecodedUrl.c_str(), url3); + free(url3); +} + +TEST(urldecode, decodesGivenUrlInPlace) +{ + const std::string expectedDecodedUrl ("http://www.geekhideout.com/urlcode.shtml"); + std::string url ("http%3a%2f%2fwww.geekhideout.com%2furlcode.shtml"); + urldecode(url); + ASSERT_STREQ(expectedDecodedUrl.c_str(), url.c_str()); +} \ No newline at end of file