https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112011-10-30T21:31:21ZRuby Issue Tracking SystemRuby master - Bug #5297: Either File.expand_path or File.join is corrupting string encodinghttps://bugs.ruby-lang.org/issues/5297?journal_id=216512011-10-30T21:31:21Zluislavena (Luis Lavena)luislavena@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>This has been solved already associated to another bug report.</p> Ruby master - Bug #5297: Either File.expand_path or File.join is corrupting string encodinghttps://bugs.ruby-lang.org/issues/5297?journal_id=242452012-03-01T02:34:15Zpatrickb (Patrick Bennett)patrick@thebennetts.com
<ul></ul><p>Which other issue is this associated with?<br>
Is this going to be patched back to 1.9.3? It's still present in 1.9.3p125</p> Ruby master - Bug #5297: Either File.expand_path or File.join is corrupting string encodinghttps://bugs.ruby-lang.org/issues/5297?journal_id=242462012-03-01T02:48:40Zluislavena (Luis Lavena)luislavena@gmail.com
<ul></ul><p>Patrick Bennett wrote:</p>
<blockquote>
<p>Which other issue is this associated with?<br>
Is this going to be patched back to 1.9.3? It's still present in 1.9.3p125</p>
</blockquote>
<p>Sorry, but with released patchlevel 125 I can no longer reproduce this:</p>
<pre>
V:\fóñè>ruby -v
ruby 1.9.3p125 (2012-02-16) [i386-mingw32]
V:\fóñè>date /T
29/02/2012
V:\fóñè>time /T
02:46 p.m.
V:\fóñè>chcp
Active code page: 1252
V:\fóñè>ruby -e "puts Encoding.default_external"
Windows-1252
V:\fóñè>irb
irb(main):001:0> a = File.expand_path "."
=> "V:/fóñè"
irb(main):002:0> a.encoding
=> #
irb(main):003:0> b = Dir.glob("../*")[1]
=> "../fóñè"
irb(main):004:0> b.encoding
=> #
irb(main):005:0> c = File.expand_path b
=> "V:/fóñè"
irb(main):006:0> c.encoding
=> #
irb(main):007:0> d = File.join(a, "foo")
=> "V:/fóñè/foo"
irb(main):008:0> d.encoding
=> #
irb(main):009:0> e = "#{a}/foo"
=> "V:/fóñè/foo"
irb(main):010:0> e.encoding
=> #
irb(main):011:0> File.open(d, "w+") { |f| f.puts "hi" }
=> nil
irb(main):012:0> File.open(e, "w+") { |f| f.puts "hi" }
=> nil
irb(main):013:0> exit
</pre> Ruby master - Bug #5297: Either File.expand_path or File.join is corrupting string encodinghttps://bugs.ruby-lang.org/issues/5297?journal_id=242472012-03-01T03:13:04Zpatrickb (Patrick Bennett)patrick@thebennetts.com
<ul></ul><p>With ruby 1.9.3p125 (2012-02-16) [i386-mingw32] File.join always converts to ASCII-8BIT for me no matter the encoding passed to it.<br>
So, using your irb example up through the File.join<br>
irb(main):001:0> a = File.expand_path "."<br>
=> "d:/test-streams"<br>
irb(main):002:0> a.encoding<br>
=> #<a href="Encoding:Windows-1252" class="external">Encoding:Windows-1252</a><br>
irb(main):003:0> b = Dir.glob("../*")[1]<br>
=> "../2dot4DSTree.reg"<br>
irb(main):004:0> b.encoding<br>
=> #<a href="Encoding:IBM437" class="external">Encoding:IBM437</a><br>
irb(main):005:0> c = File.expand_path b<br>
=> "d:/2dot4DSTree.reg"<br>
irb(main):006:0> c.encoding<br>
=> #<a href="Encoding:Windows-1252" class="external">Encoding:Windows-1252</a><br>
irb(main):007:0> d = File.join(a, "foo")<br>
=> "d:/test-streams/foo"<br>
irb(main):008:0> d.encoding<br>
=> #<a href="Encoding:ASCII-8BIT" class="external">Encoding:ASCII-8BIT</a><br>
irb(main):009:0> File.join('foo','bar').encoding<br>
=> #<a href="Encoding:ASCII-8BIT" class="external">Encoding:ASCII-8BIT</a></p>
<p>The result is the same regardless of my default external codepage - if I change it to 1252 as you have it then b's encoding returns as 1252 instead of 437 (my default) but File.join still returns as ascii-8bit. The fact that we;re apparently using the same ruby version is a little troubling though.</p> Ruby master - Bug #5297: Either File.expand_path or File.join is corrupting string encodinghttps://bugs.ruby-lang.org/issues/5297?journal_id=242482012-03-01T03:17:37Zluislavena (Luis Lavena)luislavena@gmail.com
<ul></ul><p>Patrick Bennett wrote:</p>
<blockquote>
<p>With ruby 1.9.3p125 (2012-02-16) [i386-mingw32] File.join always converts to ASCII-8BIT for me no matter the encoding passed to it.</p>
<p>=> #<a href="Encoding:ASCII-8BIT" class="external">Encoding:ASCII-8BIT</a></p>
<p>The result is the same regardless of my default external codepage - if I change it to 1252 as you have it then b's encoding returns as 1252 instead of 437 (my default) but File.join still returns as ascii-8bit. The fact that we;re apparently using the same ruby version is a little troubling though.</p>
</blockquote>
<p>The problem is your system encoding.</p>
<p>For some reason from IBM437 to Windows-1252 on Dir.glob is not working.</p>
<p>Please open a separate issue.</p>
<p>The issue described here is about File.join messing with encoding and causing File.open to fail.</p>