summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rust/libnewsboat/src/utils.rs7
-rw-r--r--test/utils.cpp8
2 files changed, 14 insertions, 1 deletions
diff --git a/rust/libnewsboat/src/utils.rs b/rust/libnewsboat/src/utils.rs
index 54328072..5a79d94b 100644
--- a/rust/libnewsboat/src/utils.rs
+++ b/rust/libnewsboat/src/utils.rs
@@ -569,7 +569,7 @@ pub fn strip_comments(line: &str) -> &str {
inside_backticks = !inside_backticks;
}
} else if chr == '#' {
- if !inside_quotes && !inside_backticks {
+ if !prev_was_backslash && !inside_quotes && !inside_backticks {
first_pound_chr_idx = idx;
break;
}
@@ -1126,5 +1126,10 @@ mod tests {
let expected = r#"some `other \` tricky # test` hehe"#;
let input = expected.to_owned() + "#here goescomment";
assert_eq!(strip_comments(&input), expected);
+
+ // Ignores escaped # characters (\\#)
+ let expected = r#"one two \# three four"#;
+ let input = expected.to_owned() + "# and a comment";
+ assert_eq!(strip_comments(&input), expected);
}
}
diff --git a/test/utils.cpp b/test/utils.cpp
index b5e9c037..7469dfc0 100644
--- a/test/utils.cpp
+++ b/test/utils.cpp
@@ -275,6 +275,14 @@ TEST_CASE(
}
}
+TEST_CASE("strip_comments ignores escaped # characters (\\#)")
+{
+ const auto expected =
+ std::string(R"#(one two \# three four)#");
+ const auto input = expected + "# and a comment";
+ REQUIRE(utils::strip_comments(input) == expected);
+}
+
TEST_CASE("strip_comments ignores # characters inside double quotes",
"[utils][issue652]")
{