Skip to content

fix(api): refactors the SQL LIKE pattern escaping logic to use a centralized utility function, ensuring consistent and secure handling of special characters across all database queries.#25

Open
tomerqodo wants to merge 4 commits into
cursor_combined_20260121_qodo_grep_cursor_copilot_1_base_fixapi_refactors_the_sql_like_pattern_escaping_logic_to_use_a_centralized__utility_function_ensuring_consistent_and_secure_handling_of_special_from
cursor_combined_20260121_qodo_grep_cursor_copilot_1_head_fixapi_refactors_the_sql_like_pattern_escaping_logic_to_use_a_centralized__utility_function_ensuring_consistent_and_secure_handling_of_special_
Open

fix(api): refactors the SQL LIKE pattern escaping logic to use a centralized utility function, ensuring consistent and secure handling of special characters across all database queries.#25
tomerqodo wants to merge 4 commits into
cursor_combined_20260121_qodo_grep_cursor_copilot_1_base_fixapi_refactors_the_sql_like_pattern_escaping_logic_to_use_a_centralized__utility_function_ensuring_consistent_and_secure_handling_of_special_from
cursor_combined_20260121_qodo_grep_cursor_copilot_1_head_fixapi_refactors_the_sql_like_pattern_escaping_logic_to_use_a_centralized__utility_function_ensuring_consistent_and_secure_handling_of_special_

Conversation

@tomerqodo

@tomerqodo tomerqodo commented Jan 21, 2026

Copy link
Copy Markdown

Benchmark PR from qodo-benchmark#431


Note

Strengthens search/query safety and consistency by standardizing SQL LIKE escaping.

  • New libs.helper.escape_like_pattern utility to escape %, _, and \ for safe LIKE/ILIKE usage
  • Refactors keyword/name/content filters in conversations, datasets (segments/child chunks), annotations, apps, tags, external knowledge APIs, workflow logs, and metadata filters to use escaped patterns with proper ESCAPE clauses
  • Updates vector backends (ClickZetta, IRIS) fallback LIKE searches to use escaped patterns and backend-specific escape syntax
  • Adds unit and integration tests covering special-character queries (%, _, \) and ensures literal matching without wildcard injection; minor test import adjustments to avoid circular dependencies

Written by Cursor Bugbot for commit b00e6e8. Configure here.

NeatGuyCoding and others added 4 commits January 21, 2026 15:54
…ralized

utility function, ensuring consistent and secure handling of special characters
across all database queries.

Signed-off-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com>
…logic

Signed-off-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

SELECT TOP {top_k} id, text, meta
FROM {self.schema}.{self.table_name}
WHERE text LIKE ?
WHERE text LIKE ? ESCAPE '|'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mismatched ESCAPE character in IRIS vector search

High Severity

The escape_like_pattern function escapes special characters using backslash (\) as the escape character, but the SQL ESCAPE '|' clause tells the database to use pipe (|) instead. This mismatch means escaped characters like \% won't be recognized as literals - the database expects |%. The LIKE pattern search will fail to correctly match special characters.

Fix in Cursor Fix in Web

case "not contains":
filters.append(json_field.notlike(f"%{value}%"))
escaped_value = escape_like_pattern(str(value))
filters.append(json_field.notlike(f"%{escaped_value}%"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing escape parameter in "not contains" filter

Medium Severity

The "not contains" case calls escape_like_pattern() but omits the escape="\\" parameter when calling notlike(). All other filter conditions ("contains", "start with", "end with") correctly include this parameter. Without it, the database won't interpret the backslash-escaped characters, so special characters in filter values will still act as wildcards.

Fix in Cursor Fix in Web

from libs.helper import escape_like_pattern

escaped_query = escape_like_pattern(query).replace("'", "''")
filter_clauses.append(f"{Field.CONTENT_KEY} LIKE '%{escaped_query}%' ESCAPE '\\\\'")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClickZetta ESCAPE clause uses wrong escape character

Medium Severity

The code sets cz.sql.string.literal.escape.mode = 'quote' which means backslashes in SQL string literals are literal characters. With this setting, ESCAPE '\\\\' becomes ESCAPE '\\' in SQL, specifying two backslashes as the escape character. However, escape_like_pattern escapes using a single backslash (e.g., 50% becomes 50\%), causing a mismatch that breaks the LIKE pattern escaping.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants