commit 0a1ea50318b316353ad219dcde7bf5fcafb4de9b
parent 856f5c0198f132b2bdc8134833aa078e92fe33b9
Author: cfillion <cfillion@users.noreply.github.com>
Date: Mon, 27 Jan 2020 03:29:02 -0500
filter: interpret quotes in the middle of a word literally
Diffstat:
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/filter.cpp b/src/filter.cpp
@@ -38,7 +38,10 @@ void Filter::set(const std::string &input)
for(size_t i = 0; i < input.size(); ++i) {
const char c = input[i];
- if((c == '"' || c == '\'') && (!quote || quote == c)) {
+ const bool isStart = buf.empty(),
+ isEnd = i+1 == input.size() || input[i+1] == '\x20';
+
+ if((c == '"' || c == '\'') && ((!quote && isStart) || (quote == c))) {
if(quote)
quote = 0;
else {
@@ -57,11 +60,11 @@ void Filter::set(const std::string &input)
}
}
else if(!quote) {
- if(c == '^' && buf.empty()) {
+ if(c == '^' && isStart) {
flags |= Node::StartAnchorFlag;
continue;
}
- else if(c == '$' && (i+1 == input.size() || input[i+1] == '\x20')) {
+ else if(c == '$' && isEnd) {
flags |= Node::EndAnchorFlag;
continue;
}
diff --git a/test/filter.cpp b/test/filter.cpp
@@ -71,7 +71,7 @@ TEST_CASE("quote phrase matching", M) {
REQUIRE_FALSE(f.match({"foo test bar baz"}));
}
-TEST_CASE("quote word matching", M) {
+TEST_CASE("full word matching", M) {
Filter f;
SECTION("double quotes")
@@ -86,6 +86,14 @@ TEST_CASE("quote word matching", M) {
REQUIRE_FALSE(f.match({"BEFOREhelloAFTER world"}));
}
+TEST_CASE("late opening quote", M) {
+ Filter f;
+ f.set("foo'bar'");
+
+ REQUIRE(f.match({"foo'bar'"}));
+ REQUIRE_FALSE(f.match({"foo bar"}));
+}
+
TEST_CASE("mixing quotes", M) {
Filter f;