aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/keymap.cpp6
-rw-r--r--test/keymap.cpp27
2 files changed, 32 insertions, 1 deletions
diff --git a/src/keymap.cpp b/src/keymap.cpp
index a11192a8..95f182b1 100644
--- a/src/keymap.cpp
+++ b/src/keymap.cpp
@@ -681,7 +681,11 @@ void KeyMap::dump_config(std::vector<std::string>& config_output) const
}
}
if (macro.second.description.size() >= 1) {
- configline.append(strprintf::fmt(R"( -- "%s")", macro.second.description));
+ const auto escaped_string = utils::replace_all(macro.second.description, {
+ {R"(\)", R"(\\)"},
+ {R"(")", R"(\")"},
+ });
+ configline.append(strprintf::fmt(R"( -- "%s")", escaped_string));
}
config_output.push_back(configline);
}
diff --git a/test/keymap.cpp b/test/keymap.cpp
index 785b5e63..f4fa30f1 100644
--- a/test/keymap.cpp
+++ b/test/keymap.cpp
@@ -488,6 +488,33 @@ TEST_CASE("dump_config() returns a line for each keybind and macro", "[KeyMap]")
}
}
+TEST_CASE("dump_config() stores a description if it is present", "[KeyMap]")
+{
+ KeyMap k(KM_NEWSBOAT);
+
+ std::vector<std::string> dumpOutput;
+
+ GIVEN("a few macros, some with a description") {
+ k.unset_all_keys("all");
+
+ k.handle_action("macro", R"(x open -- "first description")");
+ k.handle_action("macro", R"(y set m n -- "configure \"m\" \\ ")");
+ k.handle_action("macro", R"(z set var I)");
+
+ WHEN("calling dump_config()") {
+ k.dump_config(dumpOutput);
+
+ THEN("there is one line per configured macro ; all given descriptions are included") {
+ REQUIRE(dumpOutput.size() == 3);
+
+ REQUIRE(dumpOutput[0] == R"(macro x open -- "first description")");
+ REQUIRE(dumpOutput[1] == R"(macro y set "m" "n" -- "configure \"m\" \\ ")");
+ REQUIRE(dumpOutput[2] == R"(macro z set "var" "I")");
+ }
+ }
+ }
+}
+
TEST_CASE("Regression test for https://github.com/newsboat/newsboat/issues/702",
"[KeyMap]")
{