Project

General

Profile

Backport #6104

File.join always returns as ASCII-8BIT regardless of input encoding

Added by patrickb (Patrick Bennett) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:43027]

Description

I can show lots of different variations, but the simplest proof is:
irb(main):001:0> File.join('foo'.encode('utf-8')).encoding
=> #Encoding:ASCII-8BIT


Related issues

Related to Ruby master - Bug #5483: Pathname doesn’t deal with encodings properlyClosed10/25/2011Actions

Updated by luislavena (Luis Lavena) over 8 years ago

  • Category set to core
  • Assignee set to usa (Usaku NAKAMURA)

Patrick,

Actually as I described in #5297, the error is not File.join but the result of Dir.glob coming using the current Encoding.default_external and not the filesystem one:

V:>chcp 1252
Active code page: 1252

V:>ruby -e "puts Dir.glob('*').first.encoding"
Windows-1252

V:>chcp 437
Active code page: 437

V:>ruby -e "puts Dir.glob('*').first.encoding"
IBM437

While File.expand_path is more smart about that.

V:>chcp 1252
Active code page: 1252

V:>ruby -e "puts File.expand_path('.').encoding"
Windows-1252

V:>chcp 437
Active code page: 437

V:>ruby -e "puts File.expand_path('.').encoding"
Windows-1252

Updated by luislavena (Luis Lavena) over 8 years ago

Disregard previous comment, the issue with Dir.glob is something different.

irb(main):001:0> a = "foo"
=> "foo"
irb(main):002:0> a.encoding
=> #Encoding:Windows-1252
irb(main):003:0> File.join(a).encoding
=> #Encoding:ASCII-8BIT

And more:

irb(main):005:0> a = "a".encode(Encoding::UTF_8)
=> "a"
irb(main):006:0> b = "b".encode(Encoding::UTF_8)
=> "b"
irb(main):007:0> a.encoding
=> #Encoding:UTF-8
irb(main):008:0> b.encoding
=> #Encoding:UTF-8
irb(main):009:0> File.join(a, b).encoding
=> #Encoding:ASCII-8BIT

Updated by phasis68 (Heesob Park) over 8 years ago

I think this issue was solved with changeset [ruby-core:40338] [Bug #5483]">r33525.

#4

Updated by naruse (Yui NARUSE) over 8 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport193
  • Category deleted (core)
  • Target version deleted (1.9.3)
#5

Updated by naruse (Yui NARUSE) over 8 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r34865.
Patrick, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) r33525: [Backport #6104]

* file.c (rb_file_join): honor input encodings than ASCII-8BIT.
  [ruby-core:40338] [Bug #5483]

Also available in: Atom PDF