Skip to content

Fix zero-length pattern matches at the end of strings - #358

Merged
akeit0 merged 1 commit into
mainfrom
codex/fix-pattern-end-position
Oct 13, 2026
Merged

akeit0 merged 1 commit into
mainfrom
codex/fix-pattern-end-position

Conversation

@akeit0

@akeit0 akeit0 commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Pattern searches skipped the position after the last character unless the pattern itself was empty. This made string.find("abc", "$") return nil instead of (4, 3) and string.match("", "a*") return nil instead of an empty string.

Include the end position in the search loops shared by find and match, and in gmatch and gsub. Patterns requiring a character still fail there, while zero-length matches now follow Lua 5.2 behavior. Update the existing gmatch("abc", "a*") expectation to include the fourth match after c.

Add 44 regression cases covering empty inputs, end anchors, optional repetitions, position captures, start bounds, iterator termination, and substitution limits. All expected results were checked against native Lua 5.2.

Validation:

  • dotnet test --verbosity quiet: 556 runtime tests and 69 source-generator tests passed.
  • dotnet csharpier check .: all 252 files passed using the repository's pinned formatter.
  • git diff --check: passed.

@akeit0
akeit0 merged commit 48790c2 into main Oct 13, 2026
2 checks passed
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.

1 participant