Skip to content

fix: reject \NN backrefs with non-octal leading digit#40

Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-non-octal-backref-error
Draft

fix: reject \NN backrefs with non-octal leading digit#40
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-non-octal-backref-error

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

@toddr-bot toddr-bot commented Apr 10, 2026

What

Reject multi-digit backreferences like \99, \80, \89 when no matching capture group exists and octal fallback is impossible.

Why

Perl rejects these patterns as "Reference to nonexistent group" because digits 8 and 9 aren't valid octal. The parser was silently producing \000 (null) followed by literal digits — wrong output instead of an error.

How

One-line guard in the backslash-digit handler: check if the leading digit > 7 before attempting octal fallback. If so, error immediately (RPe_BGROUP). Valid octal patterns like \77 and \100 are unaffected.

Testing

  • 6 new tests in t/11errors.t (4 error cases + 2 octal fallback validations)
  • Full suite passes (676+ tests)
  • Manually verified against Perl's behavior for \77, \80, \89, \98, \99, \100

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 13 insertions(+)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Multi-digit backreferences like \99, \80, \89 where the leading digit
is 8 or 9 have no valid octal fallback (octal digits are 0-7). Previously
the parser silently produced a null character (\000) followed by literal
digits. Perl correctly rejects these as "Reference to nonexistent group".

The fix checks the leading digit before attempting octal fallback in
the backslash-digit handler. If the digit > 7, error immediately since
no valid interpretation exists.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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