Fossil SCM

When preparing a pattern for FTS search, if the pattern is empty convert it into a double-quoted empty string, to avoid FTS5 errors.

drh 2024-04-10 11:31 trunk
Commit 5bb323ff9eb82fbaa99d5c044abd729f08c605ffe8d27ace6587625a938202fe
1 file changed +5
--- src/search.c
+++ src/search.c
@@ -1005,10 +1005,15 @@
10051005
if( srchFlags==0 ) return;
10061006
sqlite3_create_function(g.db, "rank", 1, SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
10071007
search_rank_sqlfunc, 0, 0);
10081008
for(i=0; zPat[i]; i++){
10091009
if( (zPat[i]&0x80)==0 && !fossil_isalnum(zPat[i]) ) zPat[i] = ' ';
1010
+ }
1011
+ for(i--; i>=0 && zPat[i]==' '; i--){}
1012
+ if( i<0 ){
1013
+ fossil_free(zPat);
1014
+ zPat = mprintf("\"\"");
10101015
}
10111016
blob_init(&sql, 0, 0);
10121017
if( search_index_type(0)==4 ){
10131018
/* If this repo is still using the legacy FTS4 search index, then
10141019
** the snippet() function is slightly different */
10151020
--- src/search.c
+++ src/search.c
@@ -1005,10 +1005,15 @@
1005 if( srchFlags==0 ) return;
1006 sqlite3_create_function(g.db, "rank", 1, SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
1007 search_rank_sqlfunc, 0, 0);
1008 for(i=0; zPat[i]; i++){
1009 if( (zPat[i]&0x80)==0 && !fossil_isalnum(zPat[i]) ) zPat[i] = ' ';
 
 
 
 
 
1010 }
1011 blob_init(&sql, 0, 0);
1012 if( search_index_type(0)==4 ){
1013 /* If this repo is still using the legacy FTS4 search index, then
1014 ** the snippet() function is slightly different */
1015
--- src/search.c
+++ src/search.c
@@ -1005,10 +1005,15 @@
1005 if( srchFlags==0 ) return;
1006 sqlite3_create_function(g.db, "rank", 1, SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
1007 search_rank_sqlfunc, 0, 0);
1008 for(i=0; zPat[i]; i++){
1009 if( (zPat[i]&0x80)==0 && !fossil_isalnum(zPat[i]) ) zPat[i] = ' ';
1010 }
1011 for(i--; i>=0 && zPat[i]==' '; i--){}
1012 if( i<0 ){
1013 fossil_free(zPat);
1014 zPat = mprintf("\"\"");
1015 }
1016 blob_init(&sql, 0, 0);
1017 if( search_index_type(0)==4 ){
1018 /* If this repo is still using the legacy FTS4 search index, then
1019 ** the snippet() function is slightly different */
1020

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button