Project

General

Profile

Actions

Backport #5911

closed

File.expand_path produces malfunction string (it doesn't change on #encode)

Added by funny_falcon (Yura Sokolov) over 12 years ago. Updated about 12 years ago.

Status:
Closed
Assignee:
-
[ruby-core:42179]

Description

ruby-1.9.3-p0 :018 > a = "/\u043f\u0440\u0438\u0432\u0435\u0442"
 => "/привет" 
ruby-1.9.3-p0 :019 > a.bytes.to_a
 => [47, 208, 191, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130] 
ruby-1.9.3-p0 :020 > a.encoding
 => #<Encoding:UTF-8> 
ruby-1.9.3-p0 :021 > b = a.encode('cp1251')
 => "/\xEF\xF0\xE8\xE2\xE5\xF2" 
ruby-1.9.3-p0 :022 > b.bytes.to_a
 => [47, 239, 240, 232, 226, 229, 242] 
ruby-1.9.3-p0 :023 > b.encoding
 => #<Encoding:Windows-1251> 
ruby-1.9.3-p0 :024 > c = File.expand_path(b)
 => "/\xEF\xF0\xE8\xE2\xE5\xF2" 
ruby-1.9.3-p0 :025 > c.bytes.to_a
 => [47, 239, 240, 232, 226, 229, 242] 
ruby-1.9.3-p0 :026 > c.encoding
 => #<Encoding:Windows-1251> 
ruby-1.9.3-p0 :027 > d = c.encode('utf-8')
 => "/\xEF\xF0\xE8\xE2\xE5\xF2" 
ruby-1.9.3-p0 :028 > d.bytes.to_a
 => [47, 239, 240, 232, 226, 229, 242] 
ruby-1.9.3-p0 :029 > d.encoding
 => #<Encoding:UTF-8> 
ruby-1.9.3-p0 :030 > b == c
 => true 
ruby-1.9.3-p0 :031 > a == d
 => false 
ruby-1.9.3-p0 :032 > c.force_encoding(c.encoding)
 => "/\xEF\xF0\xE8\xE2\xE5\xF2" 
ruby-1.9.3-p0 :033 > e = c.encode('utf-8')
 => "/привет" 
ruby-1.9.3-p0 :034 > e.bytes.to_a
 => [47, 208, 191, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130] 
ruby-1.9.3-p0 :035 > e.encoding
 => #<Encoding:UTF-8> 
ruby-1.9.3-p0 :036 > a == e
 => true 

Initially I found this bug in Windows (with RubyInstaller).
It confirmed in Linux with ruby installed by rvm,
but not confirmed when I install same version from git repository to other path :(
So that I think bug exists, but it is very hidden.


Related issues 1 (0 open1 closed)

Related to Backport193 - Backport #5533: Pathname's raising "invalid sequence"Closedyugui (Yuki Sonoda)11/01/2011Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0