diff --git a/core/vdbe/likeop.rs b/core/vdbe/likeop.rs index 894dfdf844..98e8d8598b 100644 --- a/core/vdbe/likeop.rs +++ b/core/vdbe/likeop.rs @@ -46,10 +46,17 @@ fn construct_like_regex_with_escape(pattern: &str, escape: char) -> Regex { '%' => regex_pattern.push_str(".*"), '_' => regex_pattern.push('.'), c => { - if regex_syntax::is_meta_character(c) { - regex_pattern.push('\\'); + if c.is_ascii_alphabetic() { + regex_pattern.push('['); + regex_pattern.push(c.to_ascii_lowercase()); + regex_pattern.push(c.to_ascii_uppercase()); + regex_pattern.push(']'); + } else { + if regex_syntax::is_meta_character(c) { + regex_pattern.push('\\'); + } + regex_pattern.push(c); } - regex_pattern.push(c); } } } @@ -57,7 +64,6 @@ fn construct_like_regex_with_escape(pattern: &str, escape: char) -> Regex { regex_pattern.push('$'); RegexBuilder::new(®ex_pattern) - .case_insensitive(true) .dot_matches_new_line(true) .build() .unwrap() diff --git a/core/vdbe/value.rs b/core/vdbe/value.rs index 62dfccd27f..9e911bd7f3 100644 --- a/core/vdbe/value.rs +++ b/core/vdbe/value.rs @@ -1026,10 +1026,17 @@ pub fn construct_like_regex(pattern: &str) -> Regex { '%' => regex_pattern.push_str(".*"), '_' => regex_pattern.push('.'), ch => { - if regex_syntax::is_meta_character(c) { - regex_pattern.push('\\'); + if ch.is_ascii_alphabetic() { + regex_pattern.push('['); + regex_pattern.push(ch.to_ascii_lowercase()); + regex_pattern.push(ch.to_ascii_uppercase()); + regex_pattern.push(']'); + } else { + if regex_syntax::is_meta_character(c) { + regex_pattern.push('\\'); + } + regex_pattern.push(ch); } - regex_pattern.push(ch); } } } @@ -1037,7 +1044,6 @@ pub fn construct_like_regex(pattern: &str) -> Regex { regex_pattern.push('$'); RegexBuilder::new(®ex_pattern) - .case_insensitive(true) .dot_matches_new_line(true) .build() .unwrap() diff --git a/testing/like.test b/testing/like.test index e813d6251e..b051fed127 100755 --- a/testing/like.test +++ b/testing/like.test @@ -138,3 +138,16 @@ do_execsql_test like-fn-esc-13 { do_execsql_test like-fn-esc-14 { SELECT like('abcXX', 'abcXX', 'X') } 0 + +do_execsql_test unicode-like-case-sensitivity-1 { + SELECT like('ä', 'Ä'); +} {0} +do_execsql_test unicode-like-case-sensitivity-2 { + SELECT like('a', 'A'); +} {1} +do_execsql_test unicode-like-with-escape-1 { + SELECT like('ÄX%', 'ä%', 'X'); +} {0} +do_execsql_test unicode-like-with-escape-2 { + SELECT like('ÄX%', 'Ä%', 'X'); +} {1}