Bug #11519
closed"#{nil}" produces string as US-ASCII rather than current encoding
Description
#! /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
puts "#{bar}#{foo}".encoding
The output for this on all versions of ruby that I have except 1.9.1 is this:
Ruby version: 2.2.3
__ENCODING__ = UTF-8
UTF-8
UTF-8
UTF-8
US-ASCII
US-ASCII
US-ASCII
It is the last part that gave me grief. Rails content_for
used such a construct so all my content was being converted to US-ASCII and sometimes were error off.
It seems to me the "#{ ... }"
string should be utf-8 and so anything inserted into it should be converted to utf-8 so "#{nil}"
should be utf-8 -- not US-ASCII.
Updated by nobu (Nobuyoshi Nakada) about 9 years ago
- Description updated (diff)
- Status changed from Open to Feedback
What's and why wrong?
Updated by pedz (Perry Smith) about 9 years ago
Nobuyoshi Nakada wrote:
What's and why wrong?
“#{bar}”.encoding != ‘UTF-8’ and “#{bar}#{foo}”.encoding != ‘UTF-8’ despite foo being UTF-8 and the encoding of the source file and hence the “ … “ string within the source file being UTF-8.
Updated by Hanmac (Hans Mackowiak) about 9 years ago
hm also the order is important:
"#{}#{foo}".encoding #=> US-ASCII
"#{foo}#{}".encoding #=> UTF-8
"#{}#{foo}".encoding != "#{foo}#{}".encoding #=> true
Updated by nobu (Nobuyoshi Nakada) about 9 years ago
- Status changed from Feedback to Closed
Applied in changeset r51820.
parse.y: keep literal encoding
- parse.y (literal_concat_gen, evstr2dstr_gen): keep literal
encoding beginning with an interpolation same as the source file
encoding. [ruby-core:70703] [Bug #11519]
Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: REQUIRED
Updated by pedz (Perry Smith) about 9 years ago
Great! This is why I love the Ruby community.
Thank you!
Updated by usa (Usaku NAKAMURA) about 9 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: REQUIRED to 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: REQUIRED
Updated by usa (Usaku NAKAMURA) about 9 years ago
- Backport changed from 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: WONTFIX, 2.1: DONE, 2.2: REQUIRED
ruby_2_1 r51978 merged revision(s) 51820.
Updated by nagachika (Tomoyuki Chikanaga) almost 9 years ago
- Backport changed from 2.0.0: WONTFIX, 2.1: DONE, 2.2: REQUIRED to 2.0.0: WONTFIX, 2.1: DONE, 2.2: DONE
Backported into ruby_2_2
branch at r52773.