[ruby-core:70693] Possible encoding bug

From: Perry Smith <pedzsan@...>
Date: 2015-09-08 20:38:35 UTC
List: ruby-core #70693
Hi,

I’ve been tracking down a bug in Rails but finally came done to what might be a bug in Ruby.

Here is my sample code:

===================
#! /usr/bin/env ruby
# encoding: utf-8

puts "Ruby version: #{RUBY_VERSION}"
puts "__ENCODING__ = #{__ENCODING__}"
puts "hello".encoding
foo = "hello"
puts "#{foo}".encoding
puts "#{"hello"}".encoding
bar = nil
puts "#{bar}".encoding
puts "#{nil}".encoding
===================

The short of it is for all versions of Ruby except 1.9.1 that I tested (including the latest 2.2.3)

bar = nil
“#{bar}”.encoding => US-ASCII

which seems inconsistent to me.  In Ruby 1.9.1 it is UTF-8

Here is the output from the program above with various versions of Ruby
Ruby version: 1.9.1
__ENCODING__ = UTF-8
UTF-8
UTF-8
UTF-8
UTF-8
UTF-8

Ruby version: 1.9.3
__ENCODING__ = UTF-8
UTF-8
UTF-8
UTF-8
US-ASCII
US-ASCII

Ruby version: 1.9.3
__ENCODING__ = UTF-8
UTF-8
UTF-8
UTF-8
US-ASCII
US-ASCII

Ruby version: 2.0.0
__ENCODING__ = UTF-8
UTF-8
UTF-8
UTF-8
US-ASCII
US-ASCII

Ruby version: 2.1.0
__ENCODING__ = UTF-8
UTF-8
UTF-8
UTF-8
US-ASCII
US-ASCII

Ruby version: 2.1.2
__ENCODING__ = UTF-8
UTF-8
UTF-8
UTF-8
US-ASCII
US-ASCII

Ruby version: 2.1.4
__ENCODING__ = UTF-8
UTF-8
UTF-8
UTF-8
US-ASCII
US-ASCII

Ruby version: 2.2.3
__ENCODING__ = UTF-8
UTF-8
UTF-8
UTF-8
US-ASCII
US-ASCII

In This Thread

Prev Next