Skip to content

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

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

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

Conversation

@imsanupm

@imsanupm imsanupm commented May 4, 2026

Copy link
Copy Markdown

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 ✅

@mathiasrw mathiasrw left a comment

Copy link
Copy Markdown
Member

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
@mathiasrw

Copy link
Copy Markdown
Member

Please make a test file named test/test1978.js that will detect if we accidently reintroduces this problem.

@mathiasrw

Copy link
Copy Markdown
Member

@imsanupm are you still on this?

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