Net::Telnet support: fix regex 3-digit octal escapes in character class ranges#446
Merged
Conversation
…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>
5aac1d9 to
7834015
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Net::Telnet CPAN module support — fixes a regex preprocessing bug that prevented the module from working at runtime.
\177and\237in 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.\x{hex}format in both the character class and outside-class handlers, and add bare octal parsing to the range endpoint validator.dev/modules/net_telnet.mddocumenting the fix and Net::Telnet compatibility status.Files changed
RegexPreprocessorHelper.java— octal escape fix + range validator + dead code removalConfiguration.java— auto-updated git infodev/modules/net_telnet.md— new module support planTest plan
make— all unit tests pass./jcpan -j 4 -t Net::Telnet— 3/3 CPAN tests pass[\177],[\177-\237],[\000-\037,\177-\237], matching, substitution)re/pat.t(1067 ok) orre/regexp.t(1822/2210)Generated with Devin