summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2000-04-24 09:01:40 +0000
committerGurusamy Sarathy <gsar@cpan.org>2000-04-24 09:01:40 +0000
commit05b4157f6fee2ece5589511f927d566b229523f9 (patch)
tree440ae27b2ba4044611c795c00fb5ba855662292f
parentceda4f9bd200878375d13c58d9a0b95f9d15724b (diff)
downloadperl-05b4157f6fee2ece5589511f927d566b229523f9.tar.gz
fix RE brokenness on refs/overloaded things (from Ilya Zakharevich)
p4raw-id: //depot/perl@5931
-rw-r--r--pp_hot.c3
-rw-r--r--regexec.c6
-rwxr-xr-xt/op/pat.t19
3 files changed, 24 insertions, 4 deletions
diff --git a/pp_hot.c b/pp_hot.c
index c888ea5e71..5db5eab6f7 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1021,7 +1021,8 @@ play_it_again:
&& !PL_sawampersand
&& ((rx->reganch & ROPT_NOSCAN)
|| !((rx->reganch & RE_INTUIT_TAIL)
- && (r_flags & REXEC_SCREAM))))
+ && (r_flags & REXEC_SCREAM)))
+ && !SvROK(TARG)) /* Cannot trust since INTUIT cannot guess ^ */
goto yup;
}
if (CALLREGEXEC(aTHX_ rx, s, strend, truebase, minmatch, TARG, NULL, r_flags))
diff --git a/regexec.c b/regexec.c
index 3b6d8577a7..8f5278c254 100644
--- a/regexec.c
+++ b/regexec.c
@@ -346,7 +346,9 @@ Perl_re_intuit_start(pTHX_ regexp *prog, SV *sv, char *strpos,
I32 slen;
if ( !(prog->reganch & ROPT_ANCH_GPOS) /* Checked by the caller */
- && (sv && (strpos + SvCUR(sv) != strend)) ) {
+ /* SvCUR is not set on references: SvRV and SvPVX overlap */
+ && sv && !SvROK(sv)
+ && (strpos + SvCUR(sv) != strend)) {
DEBUG_r(PerlIO_printf(Perl_debug_log, "Not at start...\n"));
goto fail;
}
@@ -638,7 +640,7 @@ Perl_re_intuit_start(pTHX_ regexp *prog, SV *sv, char *strpos,
try_at_start:
/* Even in this situation we may use MBOL flag if strpos is offset
wrt the start of the string. */
- if (ml_anch && sv
+ if (ml_anch && sv && !SvROK(sv) /* See prev comment on SvROK */
&& (strpos + SvCUR(sv) != strend) && strpos[-1] != '\n'
/* May be due to an implicit anchor of m{.*foo} */
&& !(prog->reganch & ROPT_IMPLICIT))
diff --git a/t/op/pat.t b/t/op/pat.t
index 188a3a3b13..e00328c91f 100755
--- a/t/op/pat.t
+++ b/t/op/pat.t
@@ -4,7 +4,7 @@
# the format supported by op/regexp.t. If you want to add a test
# that does fit that format, add it to op/re_tests, not here.
-print "1..211\n";
+print "1..213\n";
BEGIN {
chdir 't' if -d 't';
@@ -995,3 +995,20 @@ $test++;
"\n\n" =~ /\n+ $ \n/x or print "not ";
print "ok $test\n";
$test++;
+
+[] =~ /^ARRAY/ or print "# [] \nnot ";
+print "ok $test\n";
+$test++;
+
+eval << 'EOE';
+{
+ package S;
+ use overload '""' => sub { 'Object S' };
+ sub new { bless [] }
+}
+$a = 'S'->new;
+EOE
+
+$a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
+print "ok $test\n";
+$test++;