Skip to content

fix: correctly handle ESCAPE character in LIKE clause (#1978)#2492

Open
imsanupm wants to merge 2 commits intoAlaSQL:developfrom
imsanupm:fix/escape-char-like-1978
Open

fix: correctly handle ESCAPE character in LIKE clause (#1978)#2492
imsanupm wants to merge 2 commits intoAlaSQL:developfrom
imsanupm:fix/escape-char-like-1978

Conversation

@imsanupm
Copy link
Copy Markdown

@imsanupm imsanupm commented May 4, 2026

Description

Fixes #1978

LIKE clause with backslash \ as ESCAPE character returned no results
instead of correctly filtering rows.

Root Cause

Two bugs in alasql.utils.like in src/15utility.js:

  1. Cache key didn't include escape character — when two queries
    used the same pattern but different escape characters, the wrong
    cached regex was reused, giving incorrect results.

  2. Backslash as escape broke regex — when \ was used as escape,
    the next character was appended as '\' + nextChar which produced
    a broken regex pattern.

Changes

  • src/15utility.js — fixed cache key to include escape character,
    and used proper regex escaping for the literal character after escape

Tests

  • 5 new regression tests all passing
  • All 2454 existing tests still passing

Verified Scenarios

  • ^ as ESCAPE works correctly ✅
  • \ as ESCAPE now works correctly ✅
  • OR condition with ESCAPE on two columns ✅
  • Same pattern with different escape chars uses separate cache entries ✅

Copy link
Copy Markdown
Member

@mathiasrw mathiasrw left a comment

Choose a reason for hiding this comment

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

We are fixing #1978

How come we create a test file for #1216 and #1953?

@imsanupm imsanupm force-pushed the fix/escape-char-like-1978 branch from ade9294 to bb69937 Compare May 6, 2026 09:13
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.

ESCAPE character issue

2 participants