Repository navigation
Treat % and _ as literals in lesson substring search - #353
Merged
Merged
Conversation
search_lessons wrapped the query in LIKE %q% without escaping metacharacters, so GET /v1/lessons?q= and /lesson search treated 100% as a prefix wildcard and foo_bar as a single-character match. Escape \, %, and _ and pair the pattern with ESCAPE '\'. Co-authored-by: Tyler Reckart <tylerreckart@users.noreply.github.com>
This was referenced Sep 18, 2026
…ke-escape # Conflicts: # CHANGELOG.md
tylerreckart
marked this pull request as ready for review
September 21, 2026 12:58
tylerreckart
enabled auto-merge (squash)
September 21, 2026 12:58
…ke-escape # Conflicts: # CHANGELOG.md
…ke-escape # Conflicts: # CHANGELOG.md
…ke-escape # Conflicts: # CHANGELOG.md
…ke-escape # Conflicts: # CHANGELOG.md
…ke-escape # Conflicts: # CHANGELOG.md
…ke-escape # Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
search_lessonsdocuments a case-insensitive substring match (GET /v1/lessons?q=,/lesson search, constitution help). The implementation wrapped the query inLIKE %q%without escaping%/_/\, so those characters were SQL wildcards.A search for
100%matcheduse 1000 CPUas well asuse 100% CPU. A search forfoo_barmatchedfooXbar. After #336 decodesq=100%25to100%, this over-match becomes the HTTP path too.This is not SQL injection (the pattern is bound), but it violates the substring contract and can surface the wrong lessons.
Fix
Escape
\,%, and_in the query and pair bothLIKEpredicates withESCAPE '\'. Unescaped ASCII queries without those characters are unchanged.Memory
tag=LIKE is left alone (separate filter; snake_case tags are a follow-up).Tests
unit_lessons6/6 locally (53 assertions) + ASan/UBSan. Existing substring / ranking cases still pass; new case covers%,_,\, and a multi-word substring that still matches.Independently mergeable against
main(0456350). Code hunks (like_literalhelper +search_lessonsSQL,test_lessons.cpp) do not overlap #321–#352 (search_lessonsand thebytes_to_hexinsertion point are identical on #322/#330/#331/#332/#348). CHANGELOG[Unreleased]will sibling-conflict after the first of those merges, same as the rest of the series.Note
Low Risk
Localized query-pattern change with tests and docs; no auth or data-migration impact.
Overview
Lesson search now treats
%,_, and\as literal characters instead of SQLiteLIKEwildcards forGET /v1/lessons?q=and/lesson search.TenantStore::search_lessonsadds alike_literalhelper that backslash-escapes those metacharacters, lowercases the query as before, and binds patterns withLIKE … ESCAPE '\'. Queries without those characters behave the same; searches like100%orfoo_barno longer over-match unrelated signatures.API docs and the changelog note the literal-substring contract. A new unit test covers
%,_,\, and normal multi-word substrings.Reviewed by Cursor Bugbot for commit 7a6822a. Bugbot is set up for automated code reviews on this repo. Configure here.