Skip to content

fix: allow escaped backslash (\\) in regex bodies - #50

Merged
gajus merged 3 commits into
gajus:mainfrom
viraatdas:libra/issues/2-regex-patterns-cannot-contain-escaped-backslash
Jun 11, 2026
Merged

fix: allow escaped backslash (\\) in regex bodies#50
gajus merged 3 commits into
gajus:mainfrom
viraatdas:libra/issues/2-regex-patterns-cannot-contain-escaped-backslash

Conversation

@viraatdas

Copy link
Copy Markdown

Fixes #49

Problem

A liqe regex body cannot contain an escaped backslash (\\), so patterns like field:/^C:\\test.*/ (Windows paths) fail to parse. The grammar's regex_body_char only allowed \ followed by a non-backslash character.

Fix

Add a grammar rule that accepts \\ and emits two literal backslashes. The generated parser (src/grammar.ts) is regenerated via npm run compile-parser and is byte-identical to the committed change, so there is no source/generated drift.

Tests

Added a regression test (path:/^C:\\test.*/) that throws before the fix and parses after. The full AVA suite passes.

libra-exla[bot] and others added 3 commits June 1, 2026 00:22
…regressions

The "escaped line terminators" test (path:/foo\<newline>bar/) parses on the
pre-fix grammar via the existing `"\\" [^\\]` rule, so it guards nothing.
Replace it with two tests that exercise the new `"\\" "\\"` rule and fail
without the fix: a trailing escaped backslash (path:/^C:\\test\\/) and a
triple-backslash sequence (foo:/a\\\b/).
@gajus
gajus merged commit 6353ab4 into gajus:main Jun 11, 2026
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 3.8.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Regex patterns cannot contain escaped backslash (\\)

2 participants