Merge branch 'develop' into feedback-service

This commit is contained in:
emeric
2023-10-31 13:48:41 +01:00
3 changed files with 35 additions and 20 deletions
+1 -1
View File
@@ -365,7 +365,7 @@ namespace API::Subsonic
void Response::JsonSerializer::serializeEscapedString(std::ostream& os, std::string_view str) void Response::JsonSerializer::serializeEscapedString(std::ostream& os, std::string_view str)
{ {
os << '\"'; os << '\"';
StringUtils::writeJSEscapedString(os, str); StringUtils::writeJsonEscapedString(os, str);
os << '\"'; os << '\"';
} }
-1
View File
@@ -52,7 +52,6 @@ namespace StringUtils
{ '\r', "\\r" }, { '\r', "\\r" },
{ '\t', "\\t" }, { '\t', "\\t" },
{ '"', "\\\"" }, { '"', "\\\"" },
{ '\'', "\\\'" },
}; };
template <std::size_t N> template <std::size_t N>
+16
View File
@@ -101,6 +101,22 @@ TEST(StringUtils, splitStringCopy)
} }
} }
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) TEST(StringUtils, escapeString)
{ {
EXPECT_EQ(StringUtils::escapeString("", "*", ' '), ""); EXPECT_EQ(StringUtils::escapeString("", "*", ' '), "");