Bug #11519
closed
"#{nil}" produces string as US-ASCII rather than current encoding
Added by pedz (Perry Smith) about 9 years ago.
Updated almost 9 years ago.
ruby -v:
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
[ruby-core:<unknown>]
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.
- Description updated (diff)
- Status changed from Open to Feedback
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.
hm also the order is important:
"#{}#{foo}".encoding #=> US-ASCII
"#{foo}#{}".encoding #=> UTF-8
"#{}#{foo}".encoding != "#{foo}#{}".encoding #=> true
- 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]
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: REQUIRED
Great! This is why I love the Ruby community.
Thank you!
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: REQUIRED to 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: REQUIRED
- 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.
- 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.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0