-
Notifications
You must be signed in to change notification settings - Fork 75
Fix: Escape ? and | characters in TokenEscaper #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9028090
70ceefb
699e332
204a50b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,11 +9,11 @@ class TokenEscaper: | |
| """ | ||
|
|
||
| # Characters that RediSearch requires us to escape during queries. | ||
| # Source: https://redis.io/docs/stack/search/reference/escaping/#the-rules-of-text-field-tokenization | ||
| DEFAULT_ESCAPED_CHARS = r"[,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ ]" | ||
| # Source: https://redis.io/docs/latest/develop/ai/search-and-query/advanced-concepts/escaping/#tokenization-rules-for-text-fields | ||
| DEFAULT_ESCAPED_CHARS = r"[,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ ?|]" | ||
|
|
||
| # Same as above but excludes * to allow wildcard patterns | ||
| ESCAPED_CHARS_NO_WILDCARD = r"[,.<>{}\[\]\\\"\':;!@#$%^&()\-+=~\/ ]" | ||
| # Same as above but excludes * and ? to allow wildcard patterns | ||
| ESCAPED_CHARS_NO_WILDCARD = r"[,.<>{}\[\]\\\"\':;!@#$%^&()\-+=~\/ |]" | ||
|
Comment on lines
+15
to
+16
|
||
|
|
||
| def __init__(self, escape_chars_re: Optional[Pattern] = None): | ||
| if escape_chars_re: | ||
|
|
@@ -27,8 +27,8 @@ def escape(self, value: str, preserve_wildcards: bool = False) -> str: | |
|
|
||
| Args: | ||
| value: The string value to escape. | ||
| preserve_wildcards: If True, preserves * characters for wildcard | ||
| matching. Defaults to False. | ||
| preserve_wildcards: If True, preserves * and ? characters for | ||
| wildcard matching. Defaults to False. | ||
|
|
||
| Returns: | ||
| The escaped string. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description says
ESCAPED_CHARS_NO_WILDCARDadded both?and|, but the code intentionally excludes?so it can be preserved whenpreserve_wildcards=True(only|is added). Please update the PR description (or the code) so they match, since this affects the documented behavior of wildcard queries.