From ad128d1bee019f32afa68aaa14c61b246ee563b3 Mon Sep 17 00:00:00 2001 From: Thomas Ubensee <34603111+tomuben@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:37:06 -0300 Subject: [PATCH] #993: Added escape sequence for \ in new Script Options parser --- .../script_options_parser/ctpg/script_option_lines_ctpg.cc | 4 +++- .../ctpg/test/script_option_lines_test.cpp | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/exaudfclient/base/script_options_parser/ctpg/script_option_lines_ctpg.cc b/exaudfclient/base/script_options_parser/ctpg/script_option_lines_ctpg.cc index b17dddab..7fcf8b05 100644 --- a/exaudfclient/base/script_options_parser/ctpg/script_option_lines_ctpg.cc +++ b/exaudfclient/base/script_options_parser/ctpg/script_option_lines_ctpg.cc @@ -61,6 +61,8 @@ const auto convert_escape_seq(std::string_view escape_seq) { retVal = "\n"; } else if (escape_seq == R"_(\r)_") { retVal = "\r"; + } else if (escape_seq == R"_(\\)_") { + retVal = "\\"; } else { throw OptionParserException(std::string("Internal parser error: Unexpected escape sequence " + std::string(escape_seq))); } @@ -91,7 +93,7 @@ const auto convert_whitespace_escape_seq(std::string_view escape_seq) { constexpr char alpha_numeric_pattern[] = R"_([0-9a-zA-Z_]+)_"; constexpr char not_semicolon_pattern[] = R"_([^;])_"; constexpr char whitespaces_pattern[] = R"_([ \x09\x0c\x0b]+)_"; -constexpr char escape_pattern[] = R"_(\\;|\\n|\\r)_"; +constexpr char escape_pattern[] = R"_(\\;|\\n|\\r|\\\\)_"; constexpr char whitespace_escape_pattern[] = R"_(\\ |\\t|\\f|\\v)_"; diff --git a/exaudfclient/base/script_options_parser/ctpg/test/script_option_lines_test.cpp b/exaudfclient/base/script_options_parser/ctpg/test/script_option_lines_test.cpp index ed22df95..6ef7e76b 100644 --- a/exaudfclient/base/script_options_parser/ctpg/test/script_option_lines_test.cpp +++ b/exaudfclient/base/script_options_parser/ctpg/test/script_option_lines_test.cpp @@ -271,6 +271,7 @@ TEST_P(ScriptOptionLinesEscapeSequenceTest, test_escape_seq_in_option_value) { '\n' -> new line character '\r' -> return character '\;' -> semicolon + '\\' -> backslash '\ ' or '\t' or '\f' or '\v' at start of option value -> replaced by the respective white space character '\ ' or '\t' or '\f' or '\v' in the middle of option value -> should not be replaced '\a' -> anything else should not be replaced. @@ -280,13 +281,17 @@ const std::vector> escape_sequences = std::make_pair("-Dhttp.agent=ABC\\nDEF", "-Dhttp.agent=ABC\nDEF"), std::make_pair("-Dhttp.agent=ABC\\rDEF", "-Dhttp.agent=ABC\rDEF"), std::make_pair("-Dhttp.agent=ABC\\;DEF", "-Dhttp.agent=ABC;DEF"), + std::make_pair("-Dhttp.agent=ABC\\\\rDEF", "-Dhttp.agent=ABC\\rDEF"), std::make_pair("-Dhttp.agent=ABC\\aDEF", "-Dhttp.agent=ABC\\aDEF"), //any other escape sequence must stay as is std::make_pair("\\n-Dhttp.agent=ABCDEF", "\n-Dhttp.agent=ABCDEF"), std::make_pair("\\r-Dhttp.agent=ABCDEF", "\r-Dhttp.agent=ABCDEF"), std::make_pair("\\;-Dhttp.agent=ABCDEF", ";-Dhttp.agent=ABCDEF"), + std::make_pair("\\\\r-Dhttp.agent=ABCDEF", "\\r-Dhttp.agent=ABCDEF"), std::make_pair("-Dhttp.agent=ABCDEF\\n", "-Dhttp.agent=ABCDEF\n"), std::make_pair("-Dhttp.agent=ABCDEF\\r", "-Dhttp.agent=ABCDEF\r"), std::make_pair("-Dhttp.agent=ABCDEF\\;", "-Dhttp.agent=ABCDEF;"), + std::make_pair("-Dhttp.agent=ABCDEF\\\\;", "-Dhttp.agent=ABCDEF\\"), + std::make_pair("-Dhttp.agent=ABCDEF\\\\\\;", "-Dhttp.agent=ABCDEF\\;"), std::make_pair("-Dhttp.agent=ABC\\ DEF", "-Dhttp.agent=ABC\\ DEF"), //escaped white space in middle of string must stay as is std::make_pair("\\ -Dhttp.agent=ABCDEF", " -Dhttp.agent=ABCDEF"), std::make_pair("\\ \t -Dhttp.agent=ABCDEF", " \t -Dhttp.agent=ABCDEF"),