Skip to content

fix(scanner): use | as LIKE escape char to stop MariaDB syntax error (#260)#279

Merged
hokiepokedad2 merged 1 commit into
mainfrom
fix/260-gym-search-sql-escape
May 22, 2026
Merged

fix(scanner): use | as LIKE escape char to stop MariaDB syntax error (#260)#279
hokiepokedad2 merged 1 commit into
mainfrom
fix/260-gym-search-sql-escape

Conversation

@hokiepokedad2
Copy link
Copy Markdown
Contributor

Summary

Fixes #260 (reported by @prof-miles0).

The gym picker (GET /api/scanner/gyms?search=...) returned no results because the underlying query was throwing a MariaDB SQL syntax error: near ''\'). The fix from #232 escaped LIKE wildcards (%, _, \) using \ as the escape character. That works in pure ANSI SQL, but MariaDB's default mode (NO_BACKSLASH_ESCAPES=OFF) treats \ as a string-literal escape too — so any user input containing a backslash (which LikeEscape itself doubles to \\) left the SQL string literal unbalanced.

Fix

Switch the LIKE escape character from \ to |. The pipe has no special meaning in MariaDB string literals, so it can't interact with quote escaping no matter what the user types.

  • LikeEscape.EscapeChar is now a public constant ("|") so callers can't drift
  • LikeEscape.Escape now doubles | (to handle user-supplied pipes), prefixes % and _
  • ScannerService.SearchGymsAsync passes LikeEscape.EscapeChar to EF.Functions.Like instead of the hardcoded "\\"
  • Backslash is no longer special — searching for Joe's \"Cafe\" works exactly like any other text

Test plan

  • CI green (EscapeLikePatternEscapesWildcardsAndEscapeChar tests pass with new expected values)
  • After merge: gym search returns results for normal terms again
  • Searching with % or _ in the term still escapes correctly (literal match, no wildcard)
  • Searching with \ in the term no longer errors (was the crash; now a no-op character)

#260)

LikeEscape (added in #232) used `\` as the SQL LIKE escape character,
and ScannerService.SearchGymsAsync passed `\` to EF.Functions.Like
via `"\\"`. MariaDB's default mode (`NO_BACKSLASH_ESCAPES=OFF`) also
treats `\` as a string-literal escape, so an escaped `\` in the
pattern (which LikeEscape itself produces for user-supplied
backslashes) left the SQL string literal unbalanced and broke gym
search with `near ''\')`.

Switch the escape character to `|`, which has no special meaning in
MariaDB string literals. The LIKE pattern can no longer interact with
quote escaping no matter what the user types. Added a `LikeEscape.EscapeChar`
constant so callers stay in sync.

Tests updated to match the new escape sequences.

Reported by @prof-miles0 in #260.
@github-actions github-actions Bot added the fix label May 22, 2026
@hokiepokedad2 hokiepokedad2 merged commit 1f5c4b7 into main May 22, 2026
6 checks passed
@hokiepokedad2 hokiepokedad2 deleted the fix/260-gym-search-sql-escape branch May 22, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gym selection tool fails to return results due to SQL syntax error

1 participant