Merge pull request #3690 from InspectorCaracal/patch-38

Avoid erroneous "direct match" targets when searching
This commit is contained in:
Griatch 2024-12-15 15:56:56 +01:00 committed by GitHub
commit bf94618e41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -552,11 +552,13 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
"""
if isinstance(searchdata, str):
candidates = kwargs.get("candidates") or []
global_search = kwargs.get("global_search", False)
match searchdata.lower():
case "me" | "self":
return True, self
return global_search or self in candidates, self
case "here":
return True, self.location
return global_search or self.location in candidates, self.location
return False, searchdata
def get_search_candidates(self, searchdata, **kwargs):
@ -836,8 +838,14 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
# replace incoming searchdata string with a potentially modified version
searchdata = self.get_search_query_replacement(searchdata, **input_kwargs)
# get candidates
candidates = self.get_search_candidates(searchdata, **input_kwargs)
# handle special input strings, like "me" or "here".
should_return, searchdata = self.get_search_direct_match(searchdata, **input_kwargs)
# we also want to include the identified candidates here instead of input, to account for defaults
should_return, searchdata = self.get_search_direct_match(
searchdata, **(input_kwargs | {"candidates": candidates})
)
if should_return:
# we got an actual result, return it immediately
return [searchdata] if quiet else searchdata
@ -857,9 +865,6 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
# always use exact match for dbref/global searches
exact = True if global_search or dbref(searchdata) else exact
# get candidates
candidates = self.get_search_candidates(searchdata, **input_kwargs)
# do the actual search
results = self.get_search_result(
searchdata,