From 89139cf8b9171f35c9a292b738281de09c5432ab Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 31 Dec 2011 23:49:01 -0800 Subject: [PATCH] [perl #103492] Make %n printf format work with Unicode It was using the internal byte count instead of the number of charac- ters. The iatter is documented. The former is useless, even for C code calling this, as later arguments could cause the current buffer to be upgraded to utf8, throwing off any offsets returned. --- sv.c | 2 +- t/op/sprintf.t | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sv.c b/sv.c index 2d8039b..8b266c3 100644 --- a/sv.c +++ b/sv.c @@ -11001,7 +11001,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *const sv, const char *const pat, const STRLEN patlen, } } else - sv_setuv_mg(argsv, (UV)i); + sv_setuv_mg(argsv, has_utf8 ? (UV)sv_len_utf8(sv) : (UV)i); continue; /* not "break" */ /* UNKNOWN */ diff --git a/t/op/sprintf.t b/t/op/sprintf.t index de1079e..05fe1de 100644 --- a/t/op/sprintf.t +++ b/t/op/sprintf.t @@ -437,6 +437,7 @@ __END__ >%m< >''< >%m INVALID< >%s< >sprintf('%%n%n %d', $n, $n)< >%n 2< >Slight sneakiness to test %n< >%s< >$n="abc"; sprintf(' %n%s', substr($n,1,1), $n)< > a1c< >%n w/magic< +>%s< >sprintf('%s%n', chr(256)x5, $n),$n< >5< >Unicode %n< >%o< >2**32-1< >37777777777< >%+o< >2**32-1< >37777777777< >%#o< >2**32-1< >037777777777< -- 2.7.4