t/re/pat_special_cc_thr.t See if special charclasses (\s \w \d) work the same as (\s and [\s]) under threads
t/re/pat.t See if esoteric patterns work
t/re/pat_thr.t See if esoteric patterns work in another thread
+t/re/pos.t Ensure pos() gets set properly after pre-match failures in pp_match
t/re/qr-72922.t Test for bug #72922
t/re/qr_gc.t See if qr doesn't leak
t/re/qrstack.t See if qr expands the stack properly
RX_MATCH_UTF8_set(rx, DO_UTF8(TARG));
+ /* We need to know this incase we fail out early - pos() must be reset */
+ global = dynpm->op_pmflags & PMf_GLOBAL;
+
/* PMdf_USED is set after a ?? matches once */
if (
#ifdef USE_ITHREADS
#endif
) {
DEBUG_r(PerlIO_printf(Perl_debug_log, "?? already matched once"));
- failure:
-
- if (gimme == G_ARRAY)
- RETURN;
- RETPUSHNO;
+ goto nope;
}
if (RX_MINLEN(rx) > (I32)len) {
DEBUG_r(PerlIO_printf(Perl_debug_log, "String shorter than min possible regex match\n"));
- goto failure;
+ goto nope;
}
truebase = t = s;
/* XXXX What part of this is needed with true \G-support? */
- if ((global = dynpm->op_pmflags & PMf_GLOBAL)) {
+ if (global) {
RX_OFFS(rx)[0].start = -1;
if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
MAGIC* const mg = mg_find(TARG, PERL_MAGIC_regex_global);
--- /dev/null
+#!./perl
+
+# Make sure pos / resetting pos on failed match works
+
+use strict;
+use warnings;
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ require './test.pl';
+}
+
+plan tests => 8;
+
+## Early bailout of pp_match because matchlen > stringlen
+
+# With a var
+{
+ my $str = "bird";
+
+ $str =~ /i/g;
+
+ is(pos($str), 2, 'pos correct');
+
+ $str =~ /toolongtomatch/g;
+
+ is(pos($str), undef, 'pos undef after failed match');
+}
+
+# With $_
+{
+ $_ = "bird";
+
+ m/i/g;
+
+ is(pos, 2, 'pos correct');
+
+ m/toolongtomatch/g;
+
+ is(pos, undef, 'pos undef after failed match');
+}
+
+## Early bail out of pp_match because ?? already matched
+
+# With a var
+{
+ my $str = "bird";
+
+ for (1..2) {
+ if ($str =~ m?bird?g) {
+ is(pos($str), 4, 'pos correct');
+ } else {
+ is(pos($str), undef, 'pos undef after failed match');
+ }
+ }
+}
+
+# With $_
+{
+ for (1..2) {
+ if (m?\d?g) {
+ is(pos, 1, 'pos correct');
+ } else {
+ is(pos, undef, 'pos undef after failed match');
+ }
+ }
+}