]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the case-insensitive version of the regexp() function so that it does not
authordrh <>
Thu, 3 Jun 2021 12:31:08 +0000 (12:31 +0000)
committerdrh <>
Thu, 3 Jun 2021 12:31:08 +0000 (12:31 +0000)
use the prefix optimization incorrectly.
[forum:/forumpost/983b43ef8e|Forum post 983b43ef8e].

FossilOrigin-Name: 1a8e43cc1b7969c40140dd7fd481d5ffd9de80e214eb494567c286d93a2b06e5

ext/misc/regexp.c
manifest
manifest.uuid
test/regexp1.test

index 03bbeb97d30d59c3823867abaeb900e52bcbc20d..204489f588c84d212a80b971abf939b21189d2cd 100644 (file)
@@ -673,7 +673,7 @@ static const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){
   ** regex engine over the string.  Do not worry able trying to match
   ** unicode characters beyond plane 0 - those are very rare and this is
   ** just an optimization. */
-  if( pRe->aOp[0]==RE_OP_ANYSTAR ){
+  if( pRe->aOp[0]==RE_OP_ANYSTAR && !noCase ){
     for(j=0, i=1; j<sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){
       unsigned x = pRe->aArg[i];
       if( x<=127 ){
@@ -719,7 +719,7 @@ static void re_sql_func(
   if( pRe==0 ){
     zPattern = (const char*)sqlite3_value_text(argv[0]);
     if( zPattern==0 ) return;
-    zErr = re_compile(&pRe, zPattern, 0);
+    zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
     if( zErr ){
       re_free(pRe);
       sqlite3_result_error(context, zErr, -1);
@@ -756,5 +756,11 @@ int sqlite3_regexp_init(
   SQLITE_EXTENSION_INIT2(pApi);
   rc = sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8|SQLITE_INNOCUOUS,
                                0, re_sql_func, 0, 0);
+  if( rc==SQLITE_OK ){
+    /* The regexpi(PATTERN,STRING) function is a case-insensitive version
+    ** of regexp(PATTERN,STRING). */
+    rc = sqlite3_create_function(db, "regexpi", 2, SQLITE_UTF8|SQLITE_INNOCUOUS,
+                                 (void*)db, re_sql_func, 0, 0);
+  }
   return rc;
 }
index ddc20c961633123858477a8a0c05288bdd405fba..f67ad18f92803e7067e67f9e1c96eb7a32a4c26f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sissue\sin\s'mkopcodeh.tcl'\stool\sthat\sprevented\sits\stermination\sin\srare\scircumstances.
-D 2021-06-01T21:07:49.044
+C Fix\sthe\scase-insensitive\sversion\sof\sthe\sregexp()\sfunction\sso\sthat\sit\sdoes\snot\nuse\sthe\sprefix\soptimization\sincorrectly.\n[forum:/forumpost/983b43ef8e|Forum\spost\s983b43ef8e].
+D 2021-06-03T12:31:08.225
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -315,7 +315,7 @@ F ext/misc/noop.c 81efe4cad9ec740e64388b14281cb983e6e2c223fed43eb77ab3e34946e0c1
 F ext/misc/normalize.c bd84355c118e297522aba74de34a4fd286fc775524e0499b14473918d09ea61f
 F ext/misc/percentile.c b9086e223d583bdaf8cb73c98a6539d501a2fc4282654adbfea576453d82e691
 F ext/misc/prefixes.c 0f4f8cff5aebc00a7e3ac4021fd59cfe1a8e17c800ceaf592859ecb9cbc38196
-F ext/misc/regexp.c 246244c714267f303df76acf73dcf110cf2eaf076896aaaba8db6d6d21a129db
+F ext/misc/regexp.c 1b9aa91151488ef5f2662449ed6e1896343f091807db739ac797a49cb2f21008
 F ext/misc/remember.c add730f0f7e7436cd15ea3fd6a90fd83c3f706ab44169f7f048438b7d6baa69c
 F ext/misc/rot13.c 51ac5f51e9d5fd811db58a9c23c628ad5f333c173f1fc53c8491a3603d38556c
 F ext/misc/scrub.c 2a44b0d44c69584c0580ad2553f6290a307a49df4668941d2812135bfb96a946
@@ -1292,7 +1292,7 @@ F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df
 F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736
 F test/rdonly.test 64e2696c322e3538df0b1ed624e21f9a23ed9ff8
 F test/recover.test ccb8c2623902a92ebb76770edd075cb4f75a4760bb7afde38026572c6e79070d
-F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8
+F test/regexp1.test 4fc575bff1440be924dbaeb0e70eb7337f6faa7cb070a221728cde650d38bc17
 F test/regexp2.test 40e894223b3d6672655481493f1be12012f2b33c
 F test/reindex.test cd9d6021729910ece82267b4f5e1b5ac2911a7566c43b43c176a6a4732e2118d
 F test/releasetest.tcl 6f803ef0b896f8f3f4c26eb072c0399963a5987a509a64d45f5dfbc1ebae2951 x
@@ -1918,7 +1918,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 587a3044468a40707c714d013cb766d8a4d9eb13bb20871846a0e8c34bea8cf4
-R 28996daffb0e59933544ba8f6a6b21ff
-U mistachkin
-Z 45822110f0419a0d61a2348a085e7f10
+P a8d921136f8ab132279984a77d0eeaf355342cdb0a98d7e1e59c8e6c8ed9459c
+R c772ab7c0e1999965225c8ce74b7eb89
+U drh
+Z 45c3bbe3107718f1b66f375ef1e2b5b3
index 4fa1d90d6b02836f990746ea658d55f91f3bdc36..328c610b61d0fc74e637e598ffbdacb5001444bf 100644 (file)
@@ -1 +1 @@
-a8d921136f8ab132279984a77d0eeaf355342cdb0a98d7e1e59c8e6c8ed9459c
\ No newline at end of file
+1a8e43cc1b7969c40140dd7fd481d5ffd9de80e214eb494567c286d93a2b06e5
\ No newline at end of file
index 0e63cd98c800973e79fe1dffd668c5b0fd4fbef5..3672b675ffe589958306c27c26b666b5eb32c5e7 100644 (file)
@@ -28,18 +28,46 @@ do_test regexp1-1.1 {
   }
 } {1 3}
 
+do_execsql_test regexp1-1.1.2 {
+  SELECT regexpi('abc','ABC');
+} {1}
+do_execsql_test regexp1-1.1.3 {
+  SELECT regexpi('ABC','ABC');
+} {1}
+do_execsql_test regexp1-1.1.4 {
+  SELECT regexpi('ABC','abc');
+} {1}
+
 do_execsql_test regexp1-1.2 {
   SELECT x FROM t1 WHERE y REGEXP 'by|in' ORDER BY x;
 } {1 2 3 4}
-do_execsql_test regexp1-1.3 {
+do_execsql_test regexp1-1.3.1 {
   SELECT x FROM t1 WHERE y REGEXP 'by|Christ' ORDER BY x;
 } {1 2 4}
+do_execsql_test regexp1-1.3.2 {
+  SELECT x FROM t1 WHERE regexp('by|christ',y) ORDER BY x;
+} {1 2}
+do_execsql_test regexp1-1.3.3 {
+  SELECT x FROM t1 WHERE regexpi('by|christ',y) ORDER BY x;
+} {1 2 4}
+do_execsql_test regexp1-1.3.4 {
+  SELECT x FROM t1 WHERE regexpi('BY|CHRIST',y) ORDER BY x;
+} {1 2 4}
 do_execsql_test regexp1-1.4 {
   SELECT x FROM t1 WHERE y REGEXP 'shal+ al+' ORDER BY x;
 } {4}
-do_execsql_test regexp1-1.5 {
+do_execsql_test regexp1-1.5.1 {
   SELECT x FROM t1 WHERE y REGEXP 'shall x*y*z*all' ORDER BY x;
 } {4}
+do_execsql_test regexp1-1.5.2 {
+  SELECT x FROM t1 WHERE regexp('shall x*y*z*all',y) ORDER BY x;
+} {4}
+do_execsql_test regexp1-1.5.3 {
+  SELECT x FROM t1 WHERE regexp('SHALL x*y*z*all',y) ORDER BY x;
+} {}
+do_execsql_test regexp1-1.5.4 {
+  SELECT x FROM t1 WHERE regexpi('SHALL x*y*z*all',y) ORDER BY x;
+} {4}
 do_execsql_test regexp1-1.6 {
   SELECT x FROM t1 WHERE y REGEXP 'shallx?y? ?z?all' ORDER BY x;
 } {4}