Skip to content

File.basename can return a string with a different encoding than the input #2259

Closed
@jordansissel

Description

@jordansissel
  • Under MRI File.basename("/foo/bar/hello world".force_encoding("Windows-31J").encoding.to_s reports "Windows-31J".
  • Under JRuby 1.7.16.1, the same code reports "UTF-8"

Having the returned string be different encoding than the input string to File.basename seems like a bug.


Full reproduction:

% rvm 2.1.4,1.7.16.1 do ruby test.rb
# Ruby 2.1.4
Windows-31J
Windows-31J

# JRuby 1.7.16.1
Windows-31J
UTF-8

Code:

# encoding: Windows-31J

x = "/hello/world"
puts x.encoding
puts File.basename(x).encoding

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions