summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexander Batischev <eual.jp@gmail.com> 2019-09-29 21:52:42 +0300
committerGravatar Alexander Batischev <eual.jp@gmail.com> 2019-10-02 13:39:31 +0300
commitb4af58a1f2f3eb97668d9e2ed4c9558ff2a8d09b (patch)
treed9321f267072371f5502d40dfa44d1f9fd50b812
parent43a8e9effec37af18b037cd3dce57a601af7b8ab (diff)
downloadnewsboat-b4af58a1f2f3eb97668d9e2ed4c9558ff2a8d09b.tar.gz
newsboat-b4af58a1f2f3eb97668d9e2ed4c9558ff2a8d09b.tar.zst
newsboat-b4af58a1f2f3eb97668d9e2ed4c9558ff2a8d09b.zip
Ignore escaped pound characters
-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]")
{