The warning appeared if the pattern contains a floating substring for
which utf8 is needed, and the target string isn't in utf8. In this
situation, downgrading the floating substring yields undef, which
triggers the warning.
Matching can't succeed in this situation, because it's impossible for
the non-utf8 target string to contain any string which needs utf8 for
its own representation. So the warning is quelled by aborting the match
early.
Anchored substrings already have a check of this form; this commit makes
the corresponding change in the floating-substring case.
STRLEN len;
const char *little;
- if (!(utf8_target ? prog->float_utf8 : prog->float_substr))
- utf8_target ? to_utf8_substr(prog) : to_byte_substr(prog);
+ if (utf8_target && !prog->float_utf8)
+ to_utf8_substr(prog);
+ else if (!utf8_target && !prog->float_substr) {
+ to_byte_substr(prog);
+ if (prog->float_substr == &PL_sv_undef)
+ /* downgrading failed, but target is not utf8, so
+ * matching must fail */
+ goto phooey;
+ }
float_real = utf8_target ? prog->float_utf8 : prog->float_substr;
little = SvPV_const(float_real, len);
}
{
+ # The second half of RT #114808
+ warning_is(sub {'aa' =~ /.+\x{100}/}, undef,
+ 'utf8-only floating substr, non-utf8 target, no warning');
+ }
+
+ {
my $message = "qr /.../x";
my $R = qr / A B C # D E/x;
ok("ABCDE" =~ $R && $& eq "ABC", $message);