summaryrefslogtreecommitdiffstats
path: root/src/test/common/test_url_escape.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/test/common/test_url_escape.cc
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/common/test_url_escape.cc')
-rw-r--r--src/test/common/test_url_escape.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/common/test_url_escape.cc b/src/test/common/test_url_escape.cc
new file mode 100644
index 00000000..6c27b64d
--- /dev/null
+++ b/src/test/common/test_url_escape.cc
@@ -0,0 +1,36 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "common/url_escape.h"
+
+#include "gtest/gtest.h"
+
+TEST(url_escape, escape) {
+ ASSERT_EQ(url_escape("foo bar"), std::string("foo%20bar"));
+ ASSERT_EQ(url_escape("foo\nbar"), std::string("foo%0abar"));
+}
+
+TEST(url_escape, unescape) {
+ ASSERT_EQ(url_unescape("foo%20bar"), std::string("foo bar"));
+ ASSERT_EQ(url_unescape("foo%0abar"), std::string("foo\nbar"));
+ ASSERT_EQ(url_unescape("%20"), std::string(" "));
+ ASSERT_EQ(url_unescape("\0%20"), std::string("\0 "));
+ ASSERT_EQ(url_unescape("\x01%20"), std::string("\x01 "));
+}
+
+TEST(url_escape, all_chars) {
+ std::string a;
+ for (unsigned j=0; j<256; ++j) {
+ a.push_back((char)j);
+ }
+ std::string b = url_escape(a);
+ std::cout << "escaped: " << b << std::endl;
+ ASSERT_EQ(a, url_unescape(b));
+}
+
+TEST(url_escape, invalid) {
+ ASSERT_THROW(url_unescape("foo%xx"), std::runtime_error);
+ ASSERT_THROW(url_unescape("foo%%"), std::runtime_error);
+ ASSERT_THROW(url_unescape("foo%"), std::runtime_error);
+ ASSERT_THROW(url_unescape("foo%0"), std::runtime_error);
+}