summaryrefslogtreecommitdiff
path: root/test/configparser.cpp
diff options
context:
space:
mode:
authorGravatar Alexander Batischev <eual.jp@gmail.com> 2019-10-02 16:30:18 +0300
committerGravatar GitHub <noreply@github.com> 2019-10-02 16:30:18 +0300
commitb3d0b966b09d1ca6cdc70e8fa7ad614041ef5bff (patch)
treea156bbfea2697c76b0d851f8f2957151cb4409fc /test/configparser.cpp
parentc63da29f70de21f045a1e40d45bcbf332ef71a4c (diff)
parent6b080e68d6d255684321a8dca669fd850152c75b (diff)
downloadnewsboat-b3d0b966b09d1ca6cdc70e8fa7ad614041ef5bff.tar.gz
newsboat-b3d0b966b09d1ca6cdc70e8fa7ad614041ef5bff.tar.zst
newsboat-b3d0b966b09d1ca6cdc70e8fa7ad614041ef5bff.zip
Merge pull request #658 from newsboat/bugfix/652-quoted-pound-sign-treated-as-comment
Ignore # characters inside double quotes and backticks Fixes #652.
Diffstat (limited to 'test/configparser.cpp')
-rw-r--r--test/configparser.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/configparser.cpp b/test/configparser.cpp
index 1133090d..f50625d8 100644
--- a/test/configparser.cpp
+++ b/test/configparser.cpp
@@ -59,6 +59,34 @@ TEST_CASE("evaluate_backticks replaces command in backticks with its output",
REQUIRE_NOTHROW(cfgparser.parse("data/config-space-backticks"));
REQUIRE_FALSE(keys.get_operation("s", "all") == OP_NIL);
}
+
+ SECTION("Unbalanced backtick does *not* start a command")
+ {
+ const auto input1 = std::string("one `echo two three");
+ REQUIRE(ConfigParser::evaluate_backticks(input1) == input1);
+
+ const auto input2 = std::string("this `echo is a` test `here");
+ const auto expected2 = std::string("this is a test `here");
+ REQUIRE(ConfigParser::evaluate_backticks(input2) == expected2);
+ }
+
+ // One might think that putting one or both backticks inside a string will
+ // "escape" them, the same way as backslash does. But it doesn't, and
+ // shouldn't: when parsing a config, we need to evaluate *all* commands
+ // there are, no matter where they're placed.
+ SECTION("Backticks inside double quotes are not ignored")
+ {
+ const auto input1 = std::string(R"#("`echo hello`")#");
+ REQUIRE(ConfigParser::evaluate_backticks(input1) == R"#("hello")#");
+
+ const auto input2 = std::string(R"#(a "b `echo c" d e` f)#");
+ // The line above asks the shell to run 'echo c" d e', which is an
+ // invalid command--the double quotes are not closed. The standard
+ // output of that command would be empty, so nothing will be inserted
+ // in place of backticks.
+ const auto expected2 = std::string(R"#(a "b f)#");
+ REQUIRE(ConfigParser::evaluate_backticks(input2) == expected2);
+ }
}
TEST_CASE("\"unbind-key -a\" removes all key bindings", "[ConfigParser]")