diff options
author | Karl Williamson <public@khwilliamson.com> | 2013-01-13 13:33:22 -0700 |
---|---|---|
committer | Karl Williamson <public@khwilliamson.com> | 2013-01-14 09:05:08 -0700 |
commit | 5e0a247b35271159d629ea8562732e0993ed4594 (patch) | |
tree | 237cc7c1643119f444e1e8fe99354454e129f578 /regcomp.c | |
parent | 5a016e9bce6eb608ca967bcbb7eb953b81f13701 (diff) | |
download | perl-5e0a247b35271159d629ea8562732e0993ed4594.tar.gz |
Add warnings for "\08", /\017/
This was discussed in thread
http://perl.markmail.org/thread/avtzvtpzemvg2ki2
but I never got around to this portion of the consensus, until now.
I did a cpan grep
http://grep.cpan.me/?q=%28^|[^\\]%29\\[0-7]{1%2C2}[8-9]&page=1
and eyeballing the results, saw three cases where this warning might
show up; one of which was for EBCDIC. The others looked to be false
positives, such as in .css files.
Diffstat (limited to 'regcomp.c')
-rw-r--r-- | regcomp.c | 34 |
1 files changed, 32 insertions, 2 deletions
@@ -535,6 +535,13 @@ static const scan_data_t zero_scan_data = Simple_vFAIL4(m, a1, a2, a3); \ } STMT_END +/* m is not necessarily a "literal string", in this macro */ +#define reg_warn_non_literal_string(loc, m) STMT_START { \ + const IV offset = loc - RExC_precomp; \ + Perl_warner(aTHX_ packWARN(WARN_REGEXP), "%s" REPORT_LOCATION, \ + m, (int)offset, RExC_precomp, RExC_precomp + offset); \ +} STMT_END + #define ckWARNreg(loc,m) STMT_START { \ const IV offset = loc - RExC_precomp; \ Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), m REPORT_LOCATION, \ @@ -10700,6 +10707,15 @@ tryagain: REQUIRE_UTF8; } p += numlen; + if (SIZE_ONLY /* like \08, \178 */ + && numlen < 3 + && p < RExC_end + && isDIGIT(*p) && ckWARN(WARN_REGEXP)) + { + reg_warn_non_literal_string( + p + 1, + form_short_octal_warning(p, numlen)); + } } else { /* Not to be treated as an octal constant, go find backref */ @@ -12166,11 +12182,25 @@ parseit: numlen = (strict) ? 4 : 3; value = grok_oct(--RExC_parse, &numlen, &flags, NULL); RExC_parse += numlen; - if (strict) { - if (numlen != 3) { + if (numlen != 3) { + SAVEFREESV(listsv); /* In case warnings are fatalized */ + if (strict) { RExC_parse += (UTF) ? UTF8SKIP(RExC_parse) : 1; vFAIL("Need exactly 3 octal digits"); } + else if (! SIZE_ONLY /* like \08, \178 */ + && numlen < 3 + && RExC_parse < RExC_end + && isDIGIT(*RExC_parse) + && ckWARN(WARN_REGEXP)) + { + SAVEFREESV(RExC_rx_sv); + reg_warn_non_literal_string( + RExC_parse + 1, + form_short_octal_warning(RExC_parse, numlen)); + (void)ReREFCNT_inc(RExC_rx_sv); + } + SvREFCNT_inc_simple_void_NN(listsv); } if (PL_encoding && value < 0x100) goto recode_encoding; |