dovecot-2.2-pigeonhole: lib-sieve: Fixed bug in `:matches' match...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Mon Feb 23 08:21:19 UTC 2015
details: http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/c8edece267cd
changeset: 1991:c8edece267cd
user: Stephan Bosch <stephan at rename-it.nl>
date: Mon Feb 23 09:21:10 2015 +0100
description:
lib-sieve: Fixed bug in `:matches' match-type that made a pattern without wildcards match as if there were a '*' at the beginning.
diffstat:
src/lib-sieve/mcht-matches.c | 65 +++++++++++++++++++++++----------------
tests/match-types/matches.svtest | 28 +++++++++++++++++
2 files changed, 66 insertions(+), 27 deletions(-)
diffs (120 lines):
diff -r e5cb9d585bc1 -r c8edece267cd src/lib-sieve/mcht-matches.c
--- a/src/lib-sieve/mcht-matches.c Sat Feb 21 18:44:30 2015 +0100
+++ b/src/lib-sieve/mcht-matches.c Mon Feb 23 09:21:10 2015 +0100
@@ -183,42 +183,53 @@
pvp = vp;
if ( next_wcard == '\0' ) {
- /* No more wildcards; find the needle substring at the end of string */
+ if ( wcard == '\0' ) {
+ /* No current wildcard; match needs to happen right at the beginning */
+ debug_printf("next_wcard = NULL && wcard = NUL; needle should be equal to value.\n");
- const char *qp, *qend;
+ if ( (vend - vp) != (nend - needle) ||
+ !cmp->def->char_match(cmp, &vp, vend, &needle, nend) ) {
+ debug_printf(" key not equal to value\n");
+ break;
+ }
- debug_printf("next_wcard = NUL; must find needle at end\n");
+ } else {
+ const char *qp, *qend;
- /* Check if the value is still large enough */
- if ( vend - str_len(section) < vp ) {
- debug_printf(" wont match: value is too short\n");
- break;
- }
+ /* No more wildcards; find the needle substring at the end of string */
+ debug_printf("next_wcard = NUL; must find needle at end\n");
- /* Move value pointer to where the needle should be */
- vp = PTR_OFFSET(vend, -str_len(section));
+ /* Check if the value is still large enough */
+ if ( vend - str_len(section) < vp ) {
+ debug_printf(" wont match: value is too short\n");
+ break;
+ }
- /* Record match values */
- qend = vp;
- qp = vp - key_offset;
+ /* Move value pointer to where the needle should be */
+ vp = PTR_OFFSET(vend, -str_len(section));
- if ( mvalues != NULL )
- str_append_n(mvalue, pvp, qp-pvp);
+ /* Record match values */
+ qend = vp;
+ qp = vp - key_offset;
- /* Compare needle to end of value string */
- if ( !cmp->def->char_match(cmp, &vp, vend, &needle, nend) ) {
- debug_printf(" match at end failed\n");
- break;
- }
+ if ( mvalues != NULL )
+ str_append_n(mvalue, pvp, qp-pvp);
- /* Add match values */
- if ( mvalues != NULL ) {
- /* Append '*' match value */
- sieve_match_values_add(mvalues, mvalue);
+ /* Compare needle to end of value string */
+ if ( !cmp->def->char_match(cmp, &vp, vend, &needle, nend) ) {
+ debug_printf(" match at end failed\n");
+ break;
+ }
- /* Append any initial '?' match values */
- for ( ; qp < qend; qp++ )
- sieve_match_values_add_char(mvalues, *qp);
+ /* Add match values */
+ if ( mvalues != NULL ) {
+ /* Append '*' match value */
+ sieve_match_values_add(mvalues, mvalue);
+
+ /* Append any initial '?' match values */
+ for ( ; qp < qend; qp++ )
+ sieve_match_values_add_char(mvalues, *qp);
+ }
}
/* Finish match */
diff -r e5cb9d585bc1 -r c8edece267cd tests/match-types/matches.svtest
--- a/tests/match-types/matches.svtest Sat Feb 21 18:44:30 2015 +0100
+++ b/tests/match-types/matches.svtest Mon Feb 23 09:21:10 2015 +0100
@@ -210,4 +210,32 @@
}
}
+test "Fixed beginning" {
+ if not header :matches "subject" "make your *" {
+ test_fail "should have matched";
+ }
+}
+test "Fixed end" {
+ if not header :matches "subject" "* very fast!!!" {
+ test_fail "should have matched";
+ }
+
+ if header :matches "subject" "* very fast!!" {
+ test_fail "should not have matched";
+ }
+}
+
+test "Fixed string" {
+ if not address :matches "to" "sirius at example.org" {
+ test_fail "should have matched";
+ }
+
+ if address :matches "to" "example.org" {
+ test_fail "should not have matched";
+ }
+
+ if address :matches "to" "sirius" {
+ test_fail "should not have matched";
+ }
+}
More information about the dovecot-cvs
mailing list