From bd162b0923e1398257c119c99bbc98f25db3f849 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 14 Feb 2026 22:56:50 +0100 Subject: [PATCH] CI: Testing fuzzy regex postgres exception. --- evennia/objects/manager.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/evennia/objects/manager.py b/evennia/objects/manager.py index 88b836d6b5..5e683d8489 100644 --- a/evennia/objects/manager.py +++ b/evennia/objects/manager.py @@ -5,6 +5,7 @@ Custom manager for Objects. import re from django.conf import settings +from django.db import connection from django.db.models import Q from django.db.models.fields import exceptions @@ -63,6 +64,19 @@ class ObjectDBManager(TypedObjectManager): # account related + @staticmethod + def _build_fuzzy_search_regex(ostring): + """ + Build a backend-compatible regex for partial word-start matching. + + PostgreSQL uses POSIX regex where `\\b` is not a word-boundary token. + """ + words = ostring.split() + if not words: + return r".*" + word_boundary = r"\m" if connection.vendor == "postgresql" else r"\b" + return r".* ".join(f"{word_boundary}{re.escape(word)}" for word in words) + r".*" + def get_object_with_account(self, ostring, exact=True, candidates=None): """ Search for an object based on its account's name or dbref. @@ -322,7 +336,7 @@ class ObjectDBManager(TypedObjectManager): ) # convert search term to partial-match regex - search_regex = r".* ".join(r"\b" + re.escape(word) for word in ostring.split()) + r".*" + search_regex = self._build_fuzzy_search_regex(ostring) # do the fuzzy search and return whatever it matches return (