Skip to content

Net::Telnet support: fix regex 3-digit octal escapes in character class ranges#446

Merged
fglock merged 1 commit into
masterfrom
feature/net-telnet-support
Apr 6, 2026
Merged

Net::Telnet support: fix regex 3-digit octal escapes in character class ranges#446
fglock merged 1 commit into
masterfrom
feature/net-telnet-support

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Apr 6, 2026

Summary

Net::Telnet CPAN module support — fixes a regex preprocessing bug that prevented the module from working at runtime.

  • Root cause: 3-digit octal escapes like \177 and \237 in character class ranges (e.g., [\177-\237]) were incorrectly parsed. The regex preprocessor only consumed the first digit and left the remaining two as literal characters, causing false "Invalid [] range" errors.
  • Fix: Convert 3-digit octal escapes to \x{hex} format in both the character class and outside-class handlers, and add bare octal parsing to the range endpoint validator.
  • Removed dead code: Two unreachable branches for 3-digit octals starting with 1-3.
  • New module plan: dev/modules/net_telnet.md documenting the fix and Net::Telnet compatibility status.

Files changed

  • RegexPreprocessorHelper.java — octal escape fix + range validator + dead code removal
  • Configuration.java — auto-updated git info
  • dev/modules/net_telnet.md — new module support plan

Test plan

  • make — all unit tests pass
  • ./jcpan -j 4 -t Net::Telnet — 3/3 CPAN tests pass
  • 15/15 regex octal escape tests pass ([\177], [\177-\237], [\000-\037,\177-\237], matching, substitution)
  • 14/14 Net::Telnet runtime tests pass (new, connect, waitfor, print, getline, cmd, timeout, error handling)
  • No regressions in re/pat.t (1067 ok) or re/regexp.t (1822/2210)

Generated with Devin

…ss ranges

Net::Telnet uses the pattern `[\000-\037,\177-\237]` to strip telnet control
characters, which crashed with "Invalid [] range" because 3-digit octal
escapes like \177 and \237 were incorrectly parsed.

Root cause: The regex preprocessor's octal handler for 3-digit sequences
(e.g., \177) only appended the first digit and didn't advance the offset,
leaving the remaining digits as literals. So \177 became \01 + "7" + "7"
instead of \x{7F} (char 127). The range validator then saw "7" (55) > "2"
(from broken \237) and errored.

Three fixes in RegexPreprocessorHelper.java:

1. Character class octal handler: Convert 3-digit octals <= 255 to \x{hex}
   format (same as the >255 path) and advance offset by octalLength-1

2. Outside-class octal handler: Same conversion to \x{hex} and offset fix

3. Range endpoint validator: Add bare octal escape parsing so the range
   validator correctly computes code points for \NNN range endpoints,
   alongside existing \x{} and \o{} support

Also removed two dead code branches (3-digit octal starting with 1-3)
that were unreachable after the preceding <= 255 && length == 3 check.

Verified: 3/3 CPAN tests, 14/14 runtime tests (connect, waitfor, print,
getline, cmd, timeout), 15/15 regex octal tests, no regressions in
re/pat.t (1067 ok) or re/regexp.t (1822/2210).

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock force-pushed the feature/net-telnet-support branch from 5aac1d9 to 7834015 Compare April 6, 2026 19:05
@fglock fglock merged commit 38ade03 into master Apr 6, 2026
2 checks passed
@fglock fglock deleted the feature/net-telnet-support branch April 6, 2026 19:20
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