]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/bugs/table_can_not_deal_with_Chinese_.mdwn
f115fbebbf18b7a6e6edbb07a3b99f3f90ed9257
[git.ikiwiki.info.git] / doc / bugs / table_can_not_deal_with_Chinese_.mdwn
1 Table directive can not deal with Chinese, when format csv
3     \[[!table format=csv data="""
4     a,b,c
5     1,2,你好
6     """
7     ]]
9 But the below example works well.
11     \[[!table format=csv data="""
12     a,b,c
13     1,2,3
14     """
15     ]]
18 The below example works well too
20     \[[!table format=dsv delimiter=, data="""
21     a,b,c
22     1,2,你好
23     """
24     ]]
26 ----
28 > You don't say what actually happens when you try this, but I hit something similar trying unicode symbols in a CSV-based table. (I wasn't aware of the DSV work-around. Thanks!) The specific error  I get trying is
30     [\[!table Error: Cannot decode string with wide characters at /usr/lib/x86_64-linux-gnu/perl/5.24/Encode.pm line 243.]]
32 > That file is owned by the `libperl5` package, but I think I've seen an error mentioning `Text::CSV` i.e. `libtext-csv-perl` when I've encountered this before. -- [[Jon]]
34 >> A related problem, also fixed by using DSV, is messing up the encoding of non-ASCII, non-wide characters, e.g. £ (workaround was to use £ instead) -- [[Jon]]
36 >>> Sorry, I have faced the same error: \[[!table Error: Cannot decode string with wide characters at /usr/lib/x86_64-linux-gnu/perl/5.24/Encode.pm line 243.]] -- [[tumashu1]]
38 ---
40 The below patch seem to deal with this problem:
42     From d6ed90331b31e4669222c6831f7a0f40f0677fe1 Mon Sep 17 00:00:00 2001
43     From: Feng Shu <tumashu@163.com>
44     Date: Sun, 2 Dec 2018 08:41:39 +0800
45     Subject: [PATCH 2/2] Fix table plugin can handle UTF-8 csv format
46     
47     ---
48      IkiWiki/Plugin/table.pm | 3 ++-
49      1 file changed, 2 insertions(+), 1 deletion(-)
50     
51     From ad1a92c796d907ad293e572a168b6e9a8219623f Mon Sep 17 00:00:00 2001
52     From: Feng Shu <tumashu@163.com>
53     Date: Sun, 2 Dec 2018 08:41:39 +0800
54     Subject: [PATCH 2/2] Fix table plugin can handle UTF-8 csv format
55     
56     ---
57      IkiWiki/Plugin/table.pm | 3 ++-
58      1 file changed, 2 insertions(+), 1 deletion(-)
59     
60     diff --git a/IkiWiki/Plugin/table.pm b/IkiWiki/Plugin/table.pm
61     index f3c425a37..7fea8ab1c 100644
62     --- a/IkiWiki/Plugin/table.pm
63     +++ b/IkiWiki/Plugin/table.pm
64     @@ -135,6 +135,7 @@ sub split_csv ($$) {
65         my $csv = Text::CSV->new({ 
66                 sep_char        => $delimiter,
67                 binary          => 1,
68     +           decode_utf8 => 1,
69                 allow_loose_quotes => 1,
70         }) || error("could not create a Text::CSV object");
71         
72     @@ -143,7 +144,7 @@ sub split_csv ($$) {
73         foreach my $line (@text_lines) {
74                 $l++;
75                 if ($csv->parse($line)) {
76     -                   push(@data, [ map { decode_utf8 $_ } $csv->fields() ]);
77     +                   push(@data, [ $csv->fields() ]);
78                 }
79                 else {
80                         debug(sprintf(gettext('parse fail at line %d: %s'), 
81     -- 
82     2.19.0
84 > Thanks, I've applied that patch and added test coverage. [[done]] --[[smcv]]
86 ----
88 I can confirm that the above patch fixes the issue for me. Thanks! I'm not an ikiwiki committer, but I would encourage them to consider the above. Whilst I'm at it, I would be *really* grateful for some input on [[todo/support_multi-row_table_headers]] which relates to the same plugin. [[Jon]]
90 ----
92 I've hit this bug with an inline-table and 3.20190228-1 (so: patch applied), with the following definition
94     [[\!table class=fullwidth_table delimiter="      " data="""    
95      
96     Number  Title   Own?    Read?    
97     I (HB1), 70 (PB1), 5 (PB50)     Dune    O       ✓"""]]
99 I'm going to attempt to work around it by moving to an external CSV. ­— [[Jon]]
101 > What version of Text::CSV (Debian: `libtext-csv-perl`) are you using?
102 > What version of Text::CSV::XS (Debian: `libtext-csv-xs-perl`) are you
103 > using, if any?
105 > I could't reproduce this with `libtext-csv-perl_2.00-1` and
106 > `libtext-csv-xs-perl_1.39-1`, assuming that the whitespace in
107 > `delimiter="..."` was meant to be a literal tab character, and that
108 > the data row has literal tabs before Dune, before O and before ✓.
110 > It would be great if you could modify `t/table.t` to include a failing
111 > test-case, and push it to your github fork or something, so I can apply
112 > it without having to guess precisely what the whitespace should be.
113 > --[[smcv]]
115 >> Sorry, I appreciate as bug reports go my last post was not that useful.
116 >> It's serving as a sort-of personal placeholder to investigate further.
117 >> The issue can be seen live [here](https://jmtd.net/fiction/sf_masterworks/),
118 >> the source is [here](https://jmtd.net/tmp/sf_masterworks.mdwn). The web
119 >> servers versions are ikiwiki                  3.20190228-1,
120 >> libtext-csv-perl         1.33-2 and libtext-csv-xs-perl is not installed.
121 >> I'll do some futher diagnosis and poking around.
122 >> ­— [[Jon]]
123 >> 
124 >> OK: issue exists with oldstable/Stretch, and is seemingly fixed in stable/Buster.
125 >> `libcsv-text-xs-perl` doesn't seem to matter (presence or absence doesn't change
126 >> the bug). Upgrading just `libtext-csv-perl` on a Stretch host with Buster's
127 >> 1.99-1 is not sufficent to fix it. As per the error, I think libperl5 might be
128 >> relevant, i.e. bug present in 5.24.1-3+deb9u5 and fixed by 5.28.1-6.
129 >>
130 >> EDIT: yes indeed merely upgrading to libperl5.28=5.28.1-6 in stretch fixes the
131 >> issue.
132 >> — [[Jon]]
133 >>
134 >> Post Buster-upgrade, and it's *still* broken on my webhost, which shows
135 >> `[\[!table Error: Wide character at /usr/lib/x86_64-linux-gnu/perl/5.28/Encode.pm line 296.]]`
136 >> with libperl5.28:amd64       5.28.1-6, libtext-csv-perl      1.99-1 and 
137 >> libtext-csv-xs-perl  1.38-1. Further fiddling will commence.
138 >> (removing libtext-csv-xs-perl does not help.)
139 — [[Jon]]