Projects

Ticket #887 (closed defect: fixed)

Opened 17 months ago

Last modified 14 months ago

calling join on an Array of BINARY Strings returns UTF-8, may raise Encoding::CompatibilityError.

Reported by: dev@… Owned by: lsansonetti@…
Priority: major Milestone: MacRuby 0.8
Component: MacRuby Keywords:
Cc: dev@…

Description

### Ruby 1.9.2
s = "a".force_encoding("BINARY")         # => "a"
s.encoding                               # => #<Encoding:ASCII-8BIT>
[s, s].join.encoding                     # => #<Encoding:ASCII-8BIT>

s = "\xA4\x01".force_encoding("BINARY")  # => "\xA4\x01"
s.encoding                               # => #<Encoding:ASCII-8BIT>
[s, s].join.encoding                     # => #<Encoding:ASCII-8BIT>


### MacRuby 0.7 trunk@4494
s = "a".force_encoding("BINARY")         # => "a"  
s.encoding                               # => #<Encoding:ASCII-8BIT>
[s, s].join.encoding                     # => #<Encoding:UTF-8>

s = "\xA4\x01".force_encoding("BINARY")  # => "\xA4\x01"
s.encoding                               # => #<Encoding:ASCII-8BIT>
[s, s].join.encoding                     # Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT

Change History

Changed 17 months ago by lsansonetti@…

  • milestone MacRuby 0.7 deleted

Indeed, looks like our #join does not honor the operands encoding. Aah, joy.

Changed 17 months ago by lsansonetti@…

Actually, it looks like MacRuby returns UTF-8 because that's what we use by default. If you add a magic comment to specify UTF-8 ruby 1.9 will behave the same. I am not sure if this is really a bug.

Changed 17 months ago by dev@…

  • cc dev@… added

Cc Me!

Changed 17 months ago by dev@…

That's not true.

#!/usr/bin/env ruby
# encoding: UTF-8
s = "a".force_encoding("BINARY")
puts s.encoding
puts [s, s].join.encoding
s = "\xA4\x01".force_encoding("BINARY")
puts s.encoding
puts [s, s].join.encoding

Gives me

ASCII-8BIT
ASCII-8BIT
ASCII-8BIT
ASCII-8BIT

With ruby 1.9.2p0 (2010-08-18 revision 29034) [universal.x86_64-darwin10.4.0]

Changed 14 months ago by watson1978@…

  • milestone set to MacRuby 1.0

Changed 14 months ago by lsansonetti@…

  • status changed from new to closed
  • resolution set to fixed
  • milestone changed from MacRuby 1.0 to MacRuby 0.8

The problem seems to be fixed with r4982.

Note: See TracTickets for help on using tickets.