https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112008-12-25T12:37:30ZRuby Issue Tracking SystemRuby master - Bug #927: [m17n] TestCSVFeatures fails because of r20905https://bugs.ruby-lang.org/issues/927?journal_id=23102008-12-25T12:37:30Zyugui (Yuki Sonoda)yugui@yugui.jp
<ul><li><strong>Category</strong> set to <i>M17N</i></li><li><strong>Priority</strong> changed from <i>3</i> to <i>Normal</i></li><li><strong>Target version</strong> set to <i>1.9.1 Release Candidate</i></li></ul><p>=begin</p>
<p>=end</p> Ruby master - Bug #927: [m17n] TestCSVFeatures fails because of r20905https://bugs.ruby-lang.org/issues/927?journal_id=23182008-12-25T15:03:01Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>=begin<br>
[Redirected to ruby-core so that James can also read this.]</p>
<p>Hello James,</p>
<p>This is an error report from Yugui about a csv test<br>
failing on a Mac.</p>
<p>The reason for the failure is line 498 in lib/csv.rb,<br>
in method CSV#inspect. This line reads:</p>
<p>str.map { |s| s.encode("ASCII-8BIT") }.join</p>
<p>The reason for the failure is that currently, filenames on a Mac<br>
are labeled as being in an "encoding" of UTF8-MAC. The label<br>
UTF8-MAC is used to mark the assumption that this string is in a<br>
character normalization form particular to the Mac (mostly NFD,<br>
but not for Korean, and not for CJKV compatibility ideographs,<br>
as far as I understand).</p>
<p>There is in general no knowledge about character normalization with<br>
respect to strings labeled UTF-8 (and even for UTF8-MAC, there is<br>
no guarantee about character normalization at all). In my personal<br>
view, the value of UTF8-MAC is questionable at least at the current<br>
point in time where we do not handle character normalization in<br>
any particular way. But for the current bug, that's actually a side<br>
issue. We might be able to fix this by introducing a (dummy) conversion<br>
from UTF8-MAC to UTF-8, but that won't actually fix the real problem.</p>
<p>The real problem is that the line above ignores that conversion<br>
to ASCII-8BIT only works for US-ASCII characters, but not for<br>
all the other characters that might appear e.g. in a filename.<br>
The easiest fix for this, which is probably what was intended,<br>
is to change the above line to</p>
<p>str.map { |s| s.force_encoding("ASCII-8BIT") }.join</p>
<p>A slightly more "user-friendly" fix is to change this to<br>
something like:</p>
<p>begin<br>
str.join<br>
rescue<br>
str.map { |s| s.force_encoding("ASCII-8BIT") }.join<br>
end</p>
<p>This will only do a force_encoding if the encodings can't<br>
be joined as is.</p>
<p>[The code above hasn't been tested; I don't have access to a Mac.]</p>
<p>Hope this helps. Regards, Martin.</p>
<p>At 12:27 08/12/25, Yugui (Yuki Sonoda) wrote:</p>
<blockquote>
<p>Yuguiです。</p>
<p>r20905で、csvのテストが失敗するようになりました。pathのエンコーディング<br>
がUTF8-MACに変わったため、CSV#inspect内でString#encodeに失敗しているよう<br>
です。<br>
これはどう扱ったらよいものでしょうか。</p>
<p>% make test-all TESTS=csv<br>
./miniruby -I../../lib -I.ext/common -I./- -r../../ext/purelib.rb<br>
../../runruby.rb --extout=.ext -- "../../test/runner.rb" csv<br>
nil<br>
Loaded suite ../../test/runner<br>
Started<br>
..........E...........................................................................................................................<br>
Finished in 0.768623 seconds.</p>
<ol>
<li>Error:<br>
test_inspect_is_smart_about_io_types(TestCSVFeatures):<br>
Encoding::ConverterNotFoundError: code converter not found (UTF8-MAC to<br>
ASCII-8BIT)<br>
/Users/yugui/src/ruby/mri/test/csv/test_features.rb:233:in <code>block in test_inspect_is_smart_about_io_types' /Users/yugui/src/ruby/mri/test/csv/test_features.rb:233:in </code>test_inspect_is_smart_about_io_types'</li>
</ol>
<p>134 tests, 1886 assertions, 0 failures, 1 errors, 0 skips<br>
make: *** [test-all] Error 1</p>
<p>--<br>
Yugui <a href="mailto:yugui@yugui.jp" class="email">yugui@yugui.jp</a><br>
<a href="http://yugui.jp" class="external">http://yugui.jp</a><br>
私は私をDumpする</p>
</blockquote>
<p>#-#-# Martin J. Du"rst, Assoc. Professor, Aoyama Gakuin University<br>
#-#-# <a href="http://www.sw.it.aoyama.ac.jp" class="external">http://www.sw.it.aoyama.ac.jp</a> <a href="mailto:duerst@it.aoyama.ac.jp" class="email">mailto:duerst@it.aoyama.ac.jp</a></p>
<p>=end</p> Ruby master - Bug #927: [m17n] TestCSVFeatures fails because of r20905https://bugs.ruby-lang.org/issues/927?journal_id=23202008-12-26T03:11:34Znaruse (Yui NARUSE)naruse@airemix.jp
<ul></ul><p>=begin<br>
成瀬です。</p>
<p>Yugui (Yuki Sonoda) wrote:</p>
<blockquote>
<p>Yuguiです。</p>
<p>r20905で、csvのテストが失敗するようになりました。pathのエンコーディング<br>
がUTF8-MACに変わったため、CSV#inspect内でString#encodeに失敗しているよう<br>
です。<br>
これはどう扱ったらよいものでしょうか。</p>
</blockquote>
<p>直感的には String#encode("ASCII-8BIT") は、<br>
String#force_encode("ASCII-8BIT") と同じ効果になるべきに感じます。</p>
<p>パッチは Encoding::Converter が絡むので少しかかる予定です。</p>
<p>--<br>
NARUSE, Yui <a href="mailto:naruse@airemix.jp" class="email">naruse@airemix.jp</a></p>
<p>=end</p> Ruby master - Bug #927: [m17n] TestCSVFeatures fails because of r20905https://bugs.ruby-lang.org/issues/927?journal_id=23272008-12-26T13:32:36Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>=begin<br>
At 03:11 08/12/26, NARUSE, Yui wrote:</p>
<blockquote>
<p>成瀬です。</p>
<p>Yugui (Yuki Sonoda) wrote:</p>
<blockquote>
<p>Yuguiです。</p>
<p>r20905で、csvのテストが失敗するようになりました。pathのエンコーディング<br>
がUTF8-MACに変わったため、CSV#inspect内でString#encodeに失敗しているよう<br>
です。<br>
これはどう扱ったらよいものでしょうか。</p>
</blockquote>
<p>直感的には String#encode("ASCII-8BIT") は、<br>
String#force_encode("ASCII-8BIT") と同じ効果になるべきに感じます。</p>
</blockquote>
<p>そういう直感は色々ありそうで、分からない来もしませんが、<br>
ここは根本的に間違っているのではないかと思います。<br>
String#encode はあくまでも文字をきちんと変換し、変換できな<br>
かったら特殊な処理をすることになっています。</p>
<p>むやみにコード変換とバイト列の解釈の変更をごっちゃ間瀬にしない方が<br>
教育の面から考えても得策かと思います。成瀬さんや私などはこの辺<br>
よく分かっていますので、心配しなくていいですが、国際化、文字コード<br>
の詳しくないプログラマはこういう特例を作るとどんどん分からなくなる<br>
おそれがあります。</p>
<p>よろしくお願いします。 Martin.</p>
<p>(<a href="https://blade.ruby-lang.org/ruby-core/20862">[ruby-core:20862]</a> 参考)</p>
<blockquote>
<p>パッチは Encoding::Converter が絡むので少しかかる予定です。</p>
<p>--<br>
NARUSE, Yui <a href="mailto:naruse@airemix.jp" class="email">naruse@airemix.jp</a></p>
</blockquote>
<p>#-#-# Martin J. Du"rst, Assoc. Professor, Aoyama Gakuin University<br>
#-#-# <a href="http://www.sw.it.aoyama.ac.jp" class="external">http://www.sw.it.aoyama.ac.jp</a> <a href="mailto:duerst@it.aoyama.ac.jp" class="email">mailto:duerst@it.aoyama.ac.jp</a></p>
<p>=end</p> Ruby master - Bug #927: [m17n] TestCSVFeatures fails because of r20905https://bugs.ruby-lang.org/issues/927?journal_id=23422008-12-27T01:57:06ZJEG2 (James Gray)jeg2@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>=begin<br>
Applied in changeset r21074.<br>
=end</p>