From 6356c94ad140bcd01b92dbba544f8e0146354d36 Mon Sep 17 00:00:00 2001 From: Toddr Bot Date: Tue, 14 Apr 2026 08:55:27 +0000 Subject: [PATCH] fix: reject incomplete \c escape at end of pattern \c requires a following character (the control character argument). When \c appeared at end of string, the handler silently produced @ (chr(64)) instead of an error. Perl rejects this as "Character following \c must be printable ASCII". Now errors with RPe_ESLASH. Co-Authored-By: Claude Opus 4.6 --- lib/Regexp/Parser/Handlers.pm | 2 +- t/11errors.t | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Regexp/Parser/Handlers.pm b/lib/Regexp/Parser/Handlers.pm index e700f73..e21e2ea 100644 --- a/lib/Regexp/Parser/Handlers.pm +++ b/lib/Regexp/Parser/Handlers.pm @@ -144,7 +144,7 @@ sub init { # control character $self->add_handler('\c' => sub { my ($S, $cc) = @_; - ${&Rx} =~ m{ \G (.?) }xgc; + $S->error($S->RPe_ESLASH) if ${&Rx} !~ m{ \G (.) }xgcs; my $c = $1; return $S->force_object(anyof_char => chr(64 ^ ord $c), "\\c$c") if $cc; return $S->object(exact => chr(64 ^ ord $c), "\\c$c"); diff --git a/t/11errors.t b/t/11errors.t index a8f5233..face90e 100644 --- a/t/11errors.t +++ b/t/11errors.t @@ -143,6 +143,9 @@ parses_ok('{abc}', '{abc} is literal text'); fails_regex('abc\\', ($r->RPe_ESLASH)[0], 'trailing backslash'); fails_regex('\\', ($r->RPe_ESLASH)[0], 'lone backslash'); +# Incomplete \c (no character follows) +fails_regex('\\c', ($r->RPe_ESLASH)[0], '\\c at end of string'); + # Missing braces on \g, \N fails_regex('\\g', ($r->RPe_BRACES)[0], '\\g without braces'); fails_regex('\\N', ($r->RPe_BRACES)[0], '\\N without braces');