Merge branch 'develop' into feedback-service
This commit is contained in:
@@ -365,7 +365,7 @@ namespace API::Subsonic
|
||||
void Response::JsonSerializer::serializeEscapedString(std::ostream& os, std::string_view str)
|
||||
{
|
||||
os << '\"';
|
||||
StringUtils::writeJSEscapedString(os, str);
|
||||
StringUtils::writeJsonEscapedString(os, str);
|
||||
os << '\"';
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,6 @@ namespace StringUtils
|
||||
{ '\r', "\\r" },
|
||||
{ '\t', "\\t" },
|
||||
{ '"', "\\\"" },
|
||||
{ '\'', "\\\'" },
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
|
||||
@@ -27,50 +27,50 @@
|
||||
TEST(StringUtils, splitString)
|
||||
{
|
||||
{
|
||||
const std::string test {"a"};
|
||||
const std::string test{ "a" };
|
||||
|
||||
const std::vector<std::string_view> strings {StringUtils::splitString(test, "")};
|
||||
const std::vector<std::string_view> strings{ StringUtils::splitString(test, "") };
|
||||
ASSERT_EQ(strings.size(), 1);
|
||||
EXPECT_EQ(strings.front() , "a");
|
||||
EXPECT_EQ(strings.front(), "a");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string test {"a b"};
|
||||
const std::string test{ "a b" };
|
||||
|
||||
const std::vector<std::string_view> strings {StringUtils::splitString(test, "|")};
|
||||
const std::vector<std::string_view> strings{ StringUtils::splitString(test, "|") };
|
||||
ASSERT_EQ(strings.size(), 1);
|
||||
EXPECT_EQ(strings.front(), "a b");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string test {" a"};
|
||||
const std::string test{ " a" };
|
||||
|
||||
const std::vector<std::string_view> strings {StringUtils::splitString(test, " ")};
|
||||
const std::vector<std::string_view> strings{ StringUtils::splitString(test, " ") };
|
||||
ASSERT_EQ(strings.size(), 1);
|
||||
EXPECT_EQ(strings.front(), "a");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string test {"a "};
|
||||
const std::string test{ "a " };
|
||||
|
||||
const std::vector<std::string_view> strings {StringUtils::splitString(test, " ")};
|
||||
const std::vector<std::string_view> strings{ StringUtils::splitString(test, " ") };
|
||||
ASSERT_EQ(strings.size(), 1);
|
||||
EXPECT_EQ(strings.front(), "a");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string test {"a b"};
|
||||
const std::string test{ "a b" };
|
||||
|
||||
const std::vector<std::string_view> strings {StringUtils::splitString(test, " ")};
|
||||
const std::vector<std::string_view> strings{ StringUtils::splitString(test, " ") };
|
||||
ASSERT_EQ(strings.size(), 2);
|
||||
EXPECT_EQ(strings.front(), "a");
|
||||
EXPECT_EQ(strings.back(), "b");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string test {"a b,c|defgh "};
|
||||
const std::string test{ "a b,c|defgh " };
|
||||
|
||||
const std::vector<std::string_view> strings {StringUtils::splitString(test, " ,|")};
|
||||
const std::vector<std::string_view> strings{ StringUtils::splitString(test, " ,|") };
|
||||
ASSERT_EQ(strings.size(), 4);
|
||||
EXPECT_EQ(strings[0], "a");
|
||||
EXPECT_EQ(strings[1], "b");
|
||||
@@ -83,24 +83,40 @@ TEST(StringUtils, splitString)
|
||||
TEST(StringUtils, splitStringCopy)
|
||||
{
|
||||
{
|
||||
const std::string test {"test=foo"};
|
||||
const std::string test{ "test=foo" };
|
||||
|
||||
const std::vector<std::string> strings {StringUtils::splitStringCopy(test, "=")};
|
||||
const std::vector<std::string> strings{ StringUtils::splitStringCopy(test, "=") };
|
||||
ASSERT_EQ(strings.size(), 2);
|
||||
EXPECT_EQ(strings[0], "test");
|
||||
EXPECT_EQ(strings[1], "foo");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string test {"test=foo bar"};
|
||||
const std::string test{ "test=foo bar" };
|
||||
|
||||
const std::vector<std::string> strings {StringUtils::splitStringCopy(test, "=")};
|
||||
const std::vector<std::string> strings{ StringUtils::splitStringCopy(test, "=") };
|
||||
ASSERT_EQ(strings.size(), 2);
|
||||
EXPECT_EQ(strings[0], "test");
|
||||
EXPECT_EQ(strings[1], "foo bar");
|
||||
}
|
||||
}
|
||||
|
||||
TEST(StringUtils, escapeJSString)
|
||||
{
|
||||
EXPECT_EQ(StringUtils::jsEscape(""), "");
|
||||
EXPECT_EQ(StringUtils::jsEscape(R"(Test'.mp3)"), R"(Test\'.mp3)");
|
||||
EXPECT_EQ(StringUtils::jsEscape(R"(Test"".mp3)"), R"(Test\"\".mp3)");
|
||||
EXPECT_EQ(StringUtils::jsEscape(R"(\Test\.mp3)"), R"(\\Test\\.mp3)");
|
||||
}
|
||||
|
||||
TEST(StringUtils, escapeJsonString)
|
||||
{
|
||||
EXPECT_EQ(StringUtils::jsonEscape(""), "");
|
||||
EXPECT_EQ(StringUtils::jsonEscape(R"(Test'.mp3)"), R"(Test'.mp3)");
|
||||
EXPECT_EQ(StringUtils::jsonEscape(R"(Test"".mp3)"), R"(Test\"\".mp3)");
|
||||
EXPECT_EQ(StringUtils::jsonEscape(R"(\Test\.mp3)"), R"(\\Test\\.mp3)");
|
||||
}
|
||||
|
||||
TEST(StringUtils, escapeString)
|
||||
{
|
||||
EXPECT_EQ(StringUtils::escapeString("", "*", ' '), "");
|
||||
@@ -145,7 +161,7 @@ TEST(StringUtils, capitalize)
|
||||
|
||||
for (const TestCase& test : tests)
|
||||
{
|
||||
std::string str {test.input};
|
||||
std::string str{ test.input };
|
||||
StringUtils::capitalize(str);
|
||||
EXPECT_EQ(str, test.expectedOutput) << " str was '" << test.input << "'";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user