New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sprintf miscounts padding when format is utf8 #7091
Comments
From schuller@lunatech.comCreated by schuller@lunatech.comThe program below demonstrates the problem: a sprintf format like #!/usr/bin/perl use warnings; my $format = '%-35s'; sub test { Perl Info
|
From @hvdsBart Schuller (via RT) <perlbug-followup@perl.org> wrote: Nice catch, please try this fix. Hugo Inline Patch--- sv.c.old Sun Jan 18 00:20:02 2004
+++ sv.c Mon Feb 9 03:15:03 2004
@@ -9507,6 +9507,9 @@
continue; /* not "break" */
}
+ /* calculate width before utf8_upgrade changes it */
+ have = esignlen + zeros + elen;
+
if (is_utf8 != has_utf8) {
if (is_utf8) {
if (SvCUR(sv))
@@ -9530,7 +9533,6 @@
"Newline in left-justified string for %sprintf",
(PL_op->op_type == OP_PRTF) ? "" : "s");
- have = esignlen + zeros + elen;
need = (have > width ? have : width);
gap = need - have;
--- t/op/sprintf2.t.old Fri Nov 28 23:57:39 2003
+++ t/op/sprintf2.t Mon Feb 9 03:18:31 2004
@@ -6,7 +6,7 @@
require './test.pl';
}
-plan tests => 2;
+plan tests => 3;
is(
sprintf("%.40g ",0.01),
@@ -18,3 +18,11 @@
sprintf("%.40f", 0.01)." ",
q(the sprintf "%.<number>f" optimization)
);
+{
+ chop(my $utf8_format = "%-3s\x{100}");
+ is(
+ sprintf($utf8_format, "\xe4"),
+ "\xe4 ",
+ q(width calculation under utf8 upgrade)
+ );
+} |
The RT System itself - Status changed from 'new' to 'open' |
From @rgshv@crypt.org wrote:
Thanks, applied as #22292. |
@rgs - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#26073 (status was 'resolved')
Searchable as RT26073$
The text was updated successfully, but these errors were encountered: