details:   https://code.tryton.org/tryton/commit/a23b86559016
branch:    default
user:      Nicolas Évrard <[email protected]>
date:      Wed Mar 18 17:23:14 2026 +0100
description:
        Consider empty string and None as incompatible with full text searches

        Closes #14691
diffstat:

 trytond/trytond/tests/test_field_char.py |  34 ++++++++++++++++++++++++++++++++
 trytond/trytond/tools/misc.py            |   2 +
 2 files changed, 36 insertions(+), 0 deletions(-)

diffs (56 lines):

diff -r cf4239a81128 -r a23b86559016 trytond/trytond/tests/test_field_char.py
--- a/trytond/trytond/tests/test_field_char.py  Wed Mar 18 16:46:38 2026 +0100
+++ b/trytond/trytond/tests/test_field_char.py  Wed Mar 18 17:23:14 2026 +0100
@@ -820,6 +820,40 @@
         pool = Pool()
         self._test_search(pool.get('test.char_translate'))
 
+    @with_transaction()
+    def test_search_empty(self):
+        "Test a full text search with an empty string"
+        pool = Pool()
+        Char = pool.get('test.char')
+
+        record1, record2 = Char.create([{
+                    'char': "word",
+                    }, {
+                    'char': "",
+                    }])
+
+        with Transaction().set_context(search_similarity=0.3):
+            self.assertEqual(
+                Char.search([('char', 'ilike', '')]),
+                [record2])
+
+    @with_transaction()
+    def test_search_null(self):
+        "Test a full text search with NULL"
+        pool = Pool()
+        Char = pool.get('test.char')
+
+        record1, record2 = Char.create([{
+                    'char': "word",
+                    }, {
+                    'char': None,
+                    }])
+
+        with Transaction().set_context(search_similarity=0.3):
+            self.assertEqual(
+                Char.search([('char', 'ilike', None)]),
+                [record2])
+
     def _test_order(self, Model):
         record1, record2 = Model.create([{
                     'char': "word",
diff -r cf4239a81128 -r a23b86559016 trytond/trytond/tools/misc.py
--- a/trytond/trytond/tools/misc.py     Wed Mar 18 16:46:38 2026 +0100
+++ b/trytond/trytond/tools/misc.py     Wed Mar 18 17:23:14 2026 +0100
@@ -223,6 +223,8 @@
 
 
 def is_full_text(value, escape='\\'):
+    if not value:
+        return False
     escaped = strip_wildcard(value, escape=escape)
     escaped = escaped.replace(escape + '%', '').replace(escape + '_', '')
     if '%' in escaped or '_' in escaped:

Reply via email to