Skip to content

Commit

Permalink
#993: Added escape sequence for \ in new Script Options parser
Browse files Browse the repository at this point in the history
  • Loading branch information
tomuben committed Oct 25, 2024
1 parent 1897b7a commit ad128d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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)_";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -280,13 +281,17 @@ const std::vector<std::pair<std::string, std::string>> 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"),
Expand Down

0 comments on commit ad128d1

Please sign in to comment.