diff --git a/ydb/core/fq/libs/common/util.cpp b/ydb/core/fq/libs/common/util.cpp index 433709568eb1..f611abff40c5 100644 --- a/ydb/core/fq/libs/common/util.cpp +++ b/ydb/core/fq/libs/common/util.cpp @@ -62,18 +62,24 @@ class TIssueDatabaseRemover { TString DatabasePath; }; +void EscapeBackslashes(TString& value) { + SubstGlobal(value, "\\", "\\\\"); +} + } TString EscapeString(const TString& value, const TString& enclosingSeq, const TString& replaceWith) { auto escapedValue = value; + EscapeBackslashes(escapedValue); SubstGlobal(escapedValue, enclosingSeq, replaceWith); return escapedValue; } TString EscapeString(const TString& value, char enclosingChar) { auto escapedValue = value; + EscapeBackslashes(escapedValue); SubstGlobal(escapedValue, TString{enclosingChar}, TStringBuilder{} << '\\' << enclosingChar); diff --git a/ydb/core/fq/libs/common/util_ut.cpp b/ydb/core/fq/libs/common/util_ut.cpp index 3e5a7d3e1202..3e209c1349c3 100644 --- a/ydb/core/fq/libs/common/util_ut.cpp +++ b/ydb/core/fq/libs/common/util_ut.cpp @@ -23,7 +23,9 @@ Y_UNIT_TEST_SUITE(EscapingBasics) { UNIT_ASSERT_VALUES_EQUAL(EscapeString("some_secret1", '"'), "some_secret1"); UNIT_ASSERT_VALUES_EQUAL(EscapeString("some_secret1", "}+{", "[*]"), "some_secret1"); UNIT_ASSERT_VALUES_EQUAL(EscapeString("some\"_\"secret1", '"'), "some\\\"_\\\"secret1"); + UNIT_ASSERT_VALUES_EQUAL(EscapeString("some\"_\\\"secret1", '"'), "some\\\"_\\\\\\\"secret1"); UNIT_ASSERT_VALUES_EQUAL(EscapeString("some}+{_}+{secret1", "}+{", "[*]"), "some[*]_[*]secret1"); + UNIT_ASSERT_VALUES_EQUAL(EscapeString("some}+{\\}+{secret1", "}+{", "[*]"), "some[*]\\\\[*]secret1"); } Y_UNIT_TEST(EncloseAndEscapeStringShouldWork) { @@ -31,7 +33,9 @@ Y_UNIT_TEST_SUITE(EscapingBasics) { UNIT_ASSERT_VALUES_EQUAL(EncloseAndEscapeString("some_secret1\nsome_secret2", "}+{", "[*]"), "}+{some_secret1\nsome_secret2}+{"); UNIT_ASSERT_VALUES_EQUAL(EncloseAndEscapeString("some\"_\"secret1", '"'), "\"some\\\"_\\\"secret1\""); + UNIT_ASSERT_VALUES_EQUAL(EncloseAndEscapeString("some\"_\\\"secret1", '"'), "\"some\\\"_\\\\\\\"secret1\""); UNIT_ASSERT_VALUES_EQUAL(EncloseAndEscapeString("some_secret1}+{\n}+{some_secret2", "}+{", "[*]"), "}+{some_secret1[*]\n[*]some_secret2}+{"); + UNIT_ASSERT_VALUES_EQUAL(EncloseAndEscapeString("some_secret1}+{\\}+{some_secret2", "}+{", "[*]"), "}+{some_secret1[*]\\\\[*]some_secret2}+{"); } }