aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbulatman <bulatman@yandex-team.com>2023-06-28 13:55:58 +0300
committerbulatman <bulatman@yandex-team.com>2023-06-28 13:55:58 +0300
commit938064d942bb0c4149dd0118ad5e0ddde2297783 (patch)
tree1b05df8c75016a5667c480143e822c300e7233c5
parent6d6a460c697933b882700556bf2344c51a789174 (diff)
downloadydb-938064d942bb0c4149dd0118ad5e0ddde2297783.tar.gz
YT: Escape back slash when format string with quotes
-rw-r--r--library/cpp/yt/string/format-inl.h2
-rw-r--r--library/cpp/yt/string/unittests/format_ut.cpp7
2 files changed, 9 insertions, 0 deletions
diff --git a/library/cpp/yt/string/format-inl.h b/library/cpp/yt/string/format-inl.h
index a6a15485eb..2eb42cfb99 100644
--- a/library/cpp/yt/string/format-inl.h
+++ b/library/cpp/yt/string/format-inl.h
@@ -91,6 +91,8 @@ inline void FormatValue(TStringBuilderBase* builder, TStringBuf value, TStringBu
builder->AppendString("\\n");
} else if (ch == '\t') {
builder->AppendString("\\t");
+ } else if (ch == '\\') {
+ builder->AppendString("\\\\");
} else if (ch < PrintableASCIILow || ch > PrintableASCIIHigh) {
builder->AppendString("\\x");
builder->AppendChar(IntToHexLowercase[static_cast<ui8>(ch) >> 4]);
diff --git a/library/cpp/yt/string/unittests/format_ut.cpp b/library/cpp/yt/string/unittests/format_ut.cpp
index 47bb4602e3..89aa01766f 100644
--- a/library/cpp/yt/string/unittests/format_ut.cpp
+++ b/library/cpp/yt/string/unittests/format_ut.cpp
@@ -148,6 +148,13 @@ TEST(TFormatTest, Quotes)
EXPECT_EQ("'\\\'\"'", Format("%qv", "\'\""));
EXPECT_EQ("\"\\x01\"", Format("%Qv", "\x1"));
EXPECT_EQ("'\\x1b'", Format("%qv", '\x1b'));
+ EXPECT_EQ("'\\\\'", Format("%qv", '\\'));
+ EXPECT_EQ("'\\n'", Format("%qv", '\n'));
+ EXPECT_EQ("'\\t'", Format("%qv", '\t'));
+ EXPECT_EQ("'\\\''", Format("%qv", '\''));
+ EXPECT_EQ("\"'\"", Format("%Qv", '\''));
+ EXPECT_EQ("'\"'", Format("%qv", '\"'));
+ EXPECT_EQ("\"\\\"\"", Format("%Qv", '\"'));
}
TEST(TFormatTest, Nullable)