summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Adam <victor@drawall.cc>2015-09-27 10:22:08 +0200
committerKarl Williamson <khw@cpan.org>2015-10-20 11:31:30 -0600
commit4a84d6e89d52b8921090805085871e6cca66924d (patch)
tree8843dbad698402cafd70e44b353fb668f3cfaeb7
parente011baf6f8ae4d213edb446fd811f9509b7abbb8 (diff)
downloadperl-4a84d6e89d52b8921090805085871e6cca66924d.tar.gz
PATCH: [perl #126181] regex: handle \cX inside (?[])
The \cX notation for control characters used to cause panics and unexpected behavior when used insed an extended character class. See bug #126181. The solution is to ignore the byte following \c during the first parsing pass of a (?[]) construct.
-rw-r--r--regcomp.c4
-rw-r--r--t/re/regex_sets.t19
2 files changed, 23 insertions, 0 deletions
diff --git a/regcomp.c b/regcomp.c
index 540f71c7fc..beec98d369 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -13444,6 +13444,10 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist,
* default: case next time and keep on incrementing until
* we find one of the invariants we do handle. */
RExC_parse++;
+ if (*RExC_parse == 'c') {
+ /* Skip the \cX notation for control characters */
+ RExC_parse++;
+ }
break;
case '[':
{
diff --git a/t/re/regex_sets.t b/t/re/regex_sets.t
index 5c683ba0a1..a5941bae88 100644
--- a/t/re/regex_sets.t
+++ b/t/re/regex_sets.t
@@ -139,6 +139,25 @@ if (! is_miniperl() && locales_enabled('LC_CTYPE')) {
}
}
+# RT #126181: \cX behaves strangely inside (?[])
+{
+ no warnings qw(syntax regexp);
+
+ eval { $_ = '/(?[(\c]) /'; qr/$_/ };
+ like($@, qr/^Syntax error/, '/(?[(\c]) / should not panic');
+ eval { $_ = '(?[\c#]' . "\n])"; qr/$_/ };
+ like($@, qr/^Syntax error/, '/(?[(\c]) / should not panic');
+ eval { $_ = '(?[(\c])'; qr/$_/ };
+ like($@, qr/^Syntax error/, '/(?[(\c])/ should be a syntax error');
+ eval { $_ = '(?[(\c]) ]\b'; qr/$_/ };
+ like($@, qr/^Syntax error/, '/(?[(\c]) ]\b/ should be a syntax error');
+ eval { $_ = '(?[\c[]](])'; qr/$_/ };
+ like($@, qr/^Syntax error/, '/(?[\c[]](])/ should be a syntax error');
+ like("\c#", qr/(?[\c#])/, '\c# should match itself');
+ like("\c[", qr/(?[\c[])/, '\c[ should match itself');
+ like("\c\ ", qr/(?[\c\])/, '\c\ should match itself');
+ like("\c]", qr/(?[\c]])/, '\c] should match itself');
+}
done_testing();