Saving locks after we set it to 0 was kind of pointless.
[p5sagit/p5-mst-13.2.git] / pp_hot.c
index 492b50b..027d124 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2117,7 +2117,14 @@ PP(pp_subst)
                break;
        } while (CALLREGEXEC(aTHX_ rx, s, strend, orig, s == m,
                             TARG, NULL, r_flags));
-       sv_catpvn(dstr, s, strend - s);
+       if (doutf8 && !DO_UTF8(dstr)) {
+           SV* nsv = sv_2mortal(newSVpvn(s, strend - s));
+           
+           sv_utf8_upgrade(nsv);
+           sv_catpvn(dstr, SvPVX(nsv), SvCUR(nsv));
+       }
+       else
+           sv_catpvn(dstr, s, strend - s);
 
        (void)SvOOK_off(TARG);
        Safefree(SvPVX(TARG));