Skip to content

Commit 550fd32

Browse files
committed
fix: Restrict single character search
1 parent d903fa1 commit 550fd32

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

fred/fred_commands/_command_utils.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@
99

1010

1111
def search(table: Type[Commands | Crashes], pattern: str, column: str, force_fuzzy: bool) -> tuple[str | list[str], bool]:
12-
"""Returns the top results based on the result.
13-
14-
This function performs an exact lookup unless `force_fuzzy` is True or no
15-
exact match is found. Fuzzy results are returned as a list of names (best
16-
matches first). The score is computed from the regex Match.fuzzy_counts()
17-
(inserts + deletes + substitutions) and used only for sorting/filtering.
18-
"""
1912

2013
if column not in dir(table):
2114
raise KeyError(f"`{column}` is not a column in the {table.__name__} table!")
2215

2316
if not force_fuzzy and (exact_match := table.fetch_by(column, pattern)):
2417
return exact_match[column], True
2518

19+
if len(pattern) < 2:
20+
raise KeyError("Search pattern must be at least 2 characters long for fuzzy searching!")
21+
2622
# Set fuzzy range - (1/3 pattern length, max 6)
2723
max_edits = min(len(pattern) // 3, 6)
2824
substring_pattern = rf".*(?:{escape(pattern)}){{e<={max_edits}}}.*"

0 commit comments

Comments
 (0)