Dne Čt 22.pro.2016 07:07:17, ppisar napsal(a):
Show quoted text> I think the bug is in Text::ASCIITable::count() that counts number of
> characters and it does these last two commands:
>
> $str = decode("utf8", $str) if $self->{options}{utf8};
> return length($str);
>
There is t/13_utf8.t test that expects exactly opposite results. It looks like Text::ASCIITable interface expects octet strings on input. I think this is terribly bad idea. Especially in these days.
Attached patch removes the undocumented utf8 feature and changes expectations that all inputs are Unicode strings.
From dcd0d8011eeaf7f74a8f03e3600235303e64f7d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 22 Dec 2016 13:12:48 +0100
Subject: [PATCH] Remove utf8 option
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This feature caused test failures since Encode-2.87 because it tried to
reinterpret input strings as UTF-8 octet stream.
It's application's responsibility to provide input as Unicode strings.
This how Perl works.
CPAN RT#118483
Signed-off-by: Petr PÃsaÅ <ppisar@redhat.com>
---
lib/Text/ASCIITable.pm | 2 --
t/03_options.t | 3 ++-
t/13_utf8.t | 5 +++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/Text/ASCIITable.pm b/lib/Text/ASCIITable.pm
index b630910..c4449e0 100644
--- a/lib/Text/ASCIITable.pm
+++ b/lib/Text/ASCIITable.pm
@@ -88,7 +88,6 @@ sub new {
$self->{options}{alignHeadRow} = $self->{options}{alignHeadRow} || 'auto'; # default setting
$self->{options}{undef_as} = $self->{options}{undef_as} || ''; # default setting
$self->{options}{chaining} = $self->{options}{chaining} || 0; # default setting
- $self->{options}{utf8} = defined($self->{options}{utf8}) ? $self->{options}{utf8} : 1; # default setting
bless $self;
@@ -884,7 +883,6 @@ sub count {
$str =~ s/<.+?>//g if $self->{options}{allowHTML};
$str =~ s/\33\[(\d+(;\d+)?)?[musfwhojBCDHRJK]//g if $self->{options}{allowANSI}; # maybe i should only have allowed ESC[#;#m and not things not related to
$str =~ s/\33\([0B]//g if $self->{options}{allowANSI}; # color/bold/underline.. But I want to give people as much room as they need.
- $str = decode("utf8", $str) if $self->{options}{utf8};
return length($str);
}
diff --git a/t/03_options.t b/t/03_options.t
index d8ef530..162c286 100644
--- a/t/03_options.t
+++ b/t/03_options.t
@@ -2,6 +2,7 @@
BEGIN { $| = 1; print "1..6\n"; }
END {print "not ok 1\n" unless $loaded;}
+use utf8;
use Text::ASCIITable;
$loaded = 1;
print "ok 1\n";
@@ -9,7 +10,7 @@ $i=2;
$t = new Text::ASCIITable({ hide_LastLine => 1, hide_HeadLine => 1 });
ok($t->setCols(['id','nick','name']));
-ok($t->addRow('1','Lunatic-|','Håkon Nessjøen'));
+ok($t->addRow('1','Lunatic-|','Håkon Nessjøen'));
$t->addRow('2','tesepe','William Viker');
$t->addRow('3','espen','Espen Ursin-Holm');
$t->addRow('4','bonde','Martin Mikkelsen');
diff --git a/t/13_utf8.t b/t/13_utf8.t
index d0ef858..59649f2 100644
--- a/t/13_utf8.t
+++ b/t/13_utf8.t
@@ -2,6 +2,7 @@
BEGIN { $| = 1; print "1..6\n"; }
END {print "not ok 1\n" unless $loaded;}
+use utf8;
use Text::ASCIITable;
$loaded = 1;
print "ok 1\n";
@@ -18,9 +19,9 @@ eval {
};
if (!$@) {ok(undef)} else {ok(1)}
@arr = split(/\n/,$content);
-ok(length($arr[3]) < length($arr[4])?undef:1);
+ok(length($arr[3]) == length($arr[4])?undef:1);
ok(length($arr[3]) == $t->getTableWidth()?undef:1);
-ok(length($arr[6]) > $t->getTableWidth()?undef:1);
+ok(length($arr[6]) == $t->getTableWidth()?undef:1);
if (scalar(@arr) == 8) {ok(undef);} else {ok(1);}
sub ok{print(defined(shift)?"not ok $i\n":"ok $i\n");$i++;}
--
2.7.4