Skip to content

Fix escaped closing brackets in Lua pattern classes - #357

Merged
akeit0 merged 2 commits into
mainfrom
codex/fix-pattern-class-escapes
Oct 13, 2026
Merged

akeit0 merged 2 commits into
mainfrom
codex/fix-pattern-class-escapes

Conversation

@akeit0

@akeit0 akeit0 commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Patterns containing an escaped closing bracket could terminate their character class too early. For example, string.find("]", "[%]]") returned nil instead of (1, 1), and the multi-element-array example in #356 failed to match.

Check the character being consumed before advancing past its escape, matching Lua 5.2.4's classend behavior. Preserve literal brackets at the start of a class and reject unterminated classes such as [%].

Add 24 regression cases covering all reported examples (including both returned positions), escaped and literal brackets, malformed classes, and shared behavior in string.match, string.gmatch, string.gsub, and frontier patterns.

Validation: dotnet test --verbosity quiet passed all 512 runtime tests and 69 source-generator tests.

Fixes #356.

@akeit0
akeit0 merged commit cc52d22 into main Oct 13, 2026
2 checks passed
@akeit0
akeit0 deleted the codex/fix-pattern-class-escapes branch October 13, 2026 03:38
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.

Inconsistent behavior of string.find with patterns

1 participant