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.#12

Open
tomerqodo wants to merge 4 commits intocursor_full_base_fixapi_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_pfrom
cursor_full_head_fixapi_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_p
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.#12
tomerqodo wants to merge 4 commits intocursor_full_base_fixapi_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_pfrom
cursor_full_head_fixapi_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_p

Conversation

@tomerqodo
Copy link
Copy Markdown

@tomerqodo tomerqodo commented Jan 25, 2026

Benchmark PR from agentic-review-benchmarks#12


Note

Improves safety and consistency of text search by standardizing SQL LIKE escaping.

  • Introduces libs.helper.escape_like_pattern and uses it across conversation, datasets_segments, services (apps, annotations, datasets, tags, workflow logs), and dataset retrieval metadata filters
  • Updates ClickZetta and IRIS VDB fallback searches to escape patterns and specify ESCAPE clauses
  • Adds integration/unit tests validating literal matching with %, _, and \ and preventing wildcard-based injections

Risk/Impact

  • Touches many query paths; search behavior may change to literal matching for special characters and relies on DB-specific ESCAPE syntax.

Written by Cursor Bugbot for commit fe99d63. Configure here.

NeatGuyCoding and others added 4 commits January 25, 2026 12:05
…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>
Copy link
Copy Markdown

@cursor cursor bot left a comment

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 2 potential issues.

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

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" LIKE clause

High Severity

The "not contains" case calls escape_like_pattern() to escape special characters but doesn't specify escape="\\" in the notlike() method. All other LIKE-based conditions ("contains", "start with", "end with") correctly include this parameter. Without specifying the escape character, the database won't know that backslash is the escape character, so escaped patterns like \% will be treated literally rather than as escaped wildcards.

Fix in Cursor Fix in Web

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 LIKE query

High Severity

The escape_like_pattern() function escapes special characters using backslash (\), but the SQL query specifies ESCAPE '|'. This mismatch means the escaping doesn't work - the database expects |% for a literal percent but receives \% instead, which will be interpreted as a literal backslash followed by a wildcard.

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