From 0999c4757999473ae2640f873d4bb05b067a4458 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sat, 2 Aug 2008 12:41:30 +0200
Subject: [PATCH] Fixed various case-sensitivily-related issues.

---
 src/lib-sieve/sieve-lexer.c              |  6 ++++--
 src/lib-sieve/sieve-validator.c          |  4 ++--
 tests/compile/trivial.sieve              | 16 +++++++++++++++-
 tests/extensions/variables/errors.svtest |  2 +-
 4 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/lib-sieve/sieve-lexer.c b/src/lib-sieve/sieve-lexer.c
index b88904446..4fa900b16 100644
--- a/src/lib-sieve/sieve-lexer.c
+++ b/src/lib-sieve/sieve-lexer.c
@@ -26,7 +26,6 @@
 #define IS_DIGIT(c) ( c >= '0' && c <= '9' )
 #define DIGIT_VAL(c) ( c - '0' )
 #define IS_ALPHA(c) ( (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') )
-#define IS_QUANTIFIER(c) (c == 'K' || c == 'M' || c =='G') 
 
 /*
  * Forward declarations
@@ -466,14 +465,17 @@ static bool sieve_lexer_scan_raw_token(struct sieve_lexer *lexer)
  			}
   		
 			switch ( sieve_lexer_curchar(lexer) ) { 
+			case 'k':
 			case 'K': /* Kilo */
 				value *= 1024;
 				sieve_lexer_shift(lexer);
-				break; 
+				break;
+			case 'm': 
 			case 'M': /* Mega */
 				value *= 1024*1024;
 				sieve_lexer_shift(lexer);
 				break;
+			case 'g':
 			case 'G': /* Giga */
 				value *= 1024*1024*1024;
 				sieve_lexer_shift(lexer);
diff --git a/src/lib-sieve/sieve-validator.c b/src/lib-sieve/sieve-validator.c
index c91d6113e..b48009e70 100644
--- a/src/lib-sieve/sieve-validator.c
+++ b/src/lib-sieve/sieve-validator.c
@@ -121,7 +121,7 @@ struct sieve_validator *sieve_validator_create
 		
 	/* Setup command registry */
 	validator->commands = hash_create
-		(default_pool, pool, 0, str_hash, (hash_cmp_callback_t *)strcmp);
+		(default_pool, pool, 0, strcase_hash, (hash_cmp_callback_t *)strcasecmp);
 	sieve_validator_register_core_commands(validator);
 	sieve_validator_register_core_tests(validator);
 	
@@ -990,7 +990,7 @@ const struct sieve_object *sieve_validator_object_registry_find
 	for ( i = 0; i < array_count(&regs->registrations); i++ ) {
 		const struct sieve_object * const *obj = array_idx(&regs->registrations, i);
 
-		if ( strcmp((*obj)->identifier, identifier) == 0)
+		if ( strcasecmp((*obj)->identifier, identifier) == 0)
 			return *obj;
 	}
 
diff --git a/tests/compile/trivial.sieve b/tests/compile/trivial.sieve
index 1bb76a9cc..4546cefa3 100644
--- a/tests/compile/trivial.sieve
+++ b/tests/compile/trivial.sieve
@@ -1,3 +1,17 @@
+# Commands must be case-insensitive
 keep;
+Keep;
+KEEP;
 discard;
-stop;
+DisCaRD;
+
+# Tags must be case-insensitive
+if size :UNDER 34 {
+}
+
+if header :Is "from" "tukker@rename-it.n" {
+}
+
+# Numbers must be case-insensitive
+if anyof( size :UNDER 34m, size :oVeR 50M ) {
+}
diff --git a/tests/extensions/variables/errors.svtest b/tests/extensions/variables/errors.svtest
index 2fbdeb516..afc130d44 100644
--- a/tests/extensions/variables/errors.svtest
+++ b/tests/extensions/variables/errors.svtest
@@ -18,7 +18,7 @@ test "Invalid set command invocations (FIXME: count only)" {
 		test_fail "compile should have failed";
 	}
 
-	if not test_error :count "eq" :comparator "i;ascii-numeric" "5" {
+	if not test_error :count "eq" :comparator "i;ascii-numeric" "6" {
 		test_fail "wrong number of errors reported";
 	}
 }
-- 
GitLab