]> git.notmuchmail.org Git - notmuch/commitdiff
Add test demonstrating a position overlap bug.
authorCarl Worth <cworth@cworth.org>
Wed, 26 Jan 2011 05:19:31 +0000 (15:19 +1000)
committerCarl Worth <cworth@cworth.org>
Wed, 26 Jan 2011 05:59:19 +0000 (15:59 +1000)
Currently, whenever we call index_terms multiple times for a single
field, the term generator is being reset to position 0 each time. This
means that with text such as:

To: a@b.c, x@y.z

one can get a bogus match by searching for:

To: a@y.c

Thanks to Mark Anderson for reporting the bug, (and providing a nice,
minimal test case that inspired what is used here).

test/notmuch-test
test/search-position-overlap-bug [new file with mode: 0755]

index fcf43a868644ad4ca95e351e9e5df771471e7f33..b2bfdff008ec81c17b5ffa4860b4a957a1e00211 100755 (executable)
@@ -16,7 +16,7 @@ fi
 
 cd $(dirname "$0")
 
 
 cd $(dirname "$0")
 
-TESTS="basic new search search-output search-by-folder json thread-naming raw reply dump-restore uuencode thread-order author-order from-guessing long-id encoding emacs maildir-sync"
+TESTS="basic new search search-output search-by-folder search-position-overlap-bug json thread-naming raw reply dump-restore uuencode thread-order author-order from-guessing long-id encoding emacs maildir-sync"
 
 # Clean up any results from a previous run
 rm -r test-results >/dev/null 2>/dev/null
 
 # Clean up any results from a previous run
 rm -r test-results >/dev/null 2>/dev/null
diff --git a/test/search-position-overlap-bug b/test/search-position-overlap-bug
new file mode 100755 (executable)
index 0000000..5bbef74
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+# Test to demonstrate a position overlap bug.
+#    
+# At one point, notmuch would index terms incorrectly in the case of
+# calling index_terms multiple times for a single field. The term
+# generator was being reset to position 0 each time. This means that
+# with text such as:
+#
+#      To: a@b.c, x@y.z
+#
+# one could get a bogus match by searching for:
+#
+#      To: a@y.c
+#    
+# Thanks to Mark Anderson for reporting the bug, (and providing a nice,
+# minimal test case that inspired what is used here), in
+# id:3wd4o8wa7fx.fsf@testarossa.amd.com
+
+test_description='that notmuch does not overlap term positions'
+. ./test-lib.sh
+
+add_message '[to]="a@b.c, x@y.z"'
+
+test_begin_subtest "Search for a@b.c matches"
+output=$(notmuch search a@b.c | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #1 (inbox unread)"
+
+test_begin_subtest "Search for x@y.z matches"
+output=$(notmuch search x@y.z | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #1 (inbox unread)"
+
+test_begin_subtest "Search for a@y.c must not match"
+output=$(notmuch search a@y.c | notmuch_search_sanitize)
+test_expect_equal "$output" ""
+
+test_done