diff options
author | Karl Williamson <khw@cpan.org> | 2020-03-19 22:17:58 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2020-03-20 07:44:31 -0600 |
commit | 293f45f699e7c79144f24b400133aca19aaa0e2e (patch) | |
tree | a1e208e339355a07d000f91cf842cda5f7f654b0 | |
parent | c08e9114637298ea7e24716942136ff527afb319 (diff) | |
download | perl-293f45f699e7c79144f24b400133aca19aaa0e2e.tar.gz |
regcomp.c: Add a [ to fake string only if original had one
This code is assembling a fake string to parse, modified from the
original. Prior to a future commit, this was only called when there was
a bracketed character class, so it made sense to unconditionally add
the bracket. But soon this will be called when there isn't a bracket,
so one shouldn't be added.
-rw-r--r-- | regcomp.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -18443,13 +18443,19 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth, /* If the character class contains anything else besides these * multi-character folds, have to include it in recursive parsing */ if (element_count) { - sv_catpvs(substitute_parse, "|["); + bool has_l_bracket = orig_parse > RExC_start && *(orig_parse - 1) == '['; + + sv_catpvs(substitute_parse, "|"); + if (has_l_bracket) { /* Add an [ if the original had one */ + sv_catpvs(substitute_parse, "["); + } constructed_prefix_len = SvCUR(substitute_parse); sv_catpvn(substitute_parse, orig_parse, RExC_parse - orig_parse); - /* Put in a closing ']' only if not going off the end, as otherwise - * we are adding something that really isn't there */ - if (RExC_parse < RExC_end) { + /* Put in a closing ']' to match any opening one, but not if going + * off the end, as otherwise we are adding something that really + * isn't there */ + if (has_l_bracket && RExC_parse < RExC_end) { sv_catpvs(substitute_parse, "]"); } } |