diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-10-20 22:01:05 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-10-21 23:15:29 +0200 |
| commit | 4dddfd622977f84f0cf41847aec9e728d02bec65 (patch) | |
| tree | 27bc4ceca8cd18bd3583107b2213368134b931f5 /test/uri.cc | |
| parent | e8dc8edad7cdf194091f0479b70b154e872f57ef (diff) | |
uri: New module
Decode URI encoded string, validating both hex and that encoded
data is valid UTF-8.
Diffstat (limited to 'test/uri.cc')
| -rw-r--r-- | test/uri.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/uri.cc b/test/uri.cc new file mode 100644 index 0000000..44366b9 --- /dev/null +++ b/test/uri.cc @@ -0,0 +1,23 @@ +#include "uri.hh" + +#include <gtest/gtest.h> +#include <string> + +TEST(uri, empty) { + std::string tmp; + EXPECT_EQ("", uri::decode("", tmp).value_or("error")); +} + +TEST(uri, example) { + std::string tmp; + EXPECT_EQ("?x=test", uri::decode("%3Fx%3Dtest", tmp).value_or("error")); + EXPECT_EQ( + "шеллы", + uri::decode("%D1%88%D0%B5%D0%BB%D0%BB%D1%8B", tmp).value_or("error")); + EXPECT_EQ("JavaScript_шеллы", + uri::decode("JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B", tmp) + .value_or("error")); + EXPECT_FALSE(uri::decode("%E0%A4%A", tmp).has_value()); + EXPECT_EQ("search+query (correct)", + uri::decode("search+query%20%28correct%29", tmp).value_or("error")); +} |
