Project

General

Profile

Bug #11519

"#{nil}" produces string as US-ASCII rather than current encoding

Added by pedz (Perry Smith) about 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
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.

Associated revisions

Revision b4efab9e
Added by nobu (Nobuyoshi Nakada) about 4 years ago

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51820 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 51820
Added by nobu (Nobuyoshi Nakada) about 4 years ago

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]

Revision 51820
Added by nobu (Nobuyoshi Nakada) about 4 years ago

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]

Revision 51820
Added by nobu (Nobuyoshi Nakada) about 4 years ago

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]

Revision 51820
Added by nobu (Nobuyoshi Nakada) about 4 years ago

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]

Revision 51820
Added by nobu (Nobuyoshi Nakada) about 4 years ago

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]

Revision d3fb88d0
Added by usa (Usaku NAKAMURA) about 4 years ago

merge revision(s) 51820: [Backport #11519]

    * 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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@51978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 51978
Added by usa (Usaku NAKAMURA) about 4 years ago

merge revision(s) 51820: [Backport #11519]

* 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]

Revision aad72320
Added by nagachika (Tomoyuki Chikanaga) almost 4 years ago

merge revision(s) 51820: [Backport #11519]

    * 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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@52773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 52773
Added by nagachika (Tomoyuki Chikanaga) almost 4 years ago

merge revision(s) 51820: [Backport #11519]

* 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]

History

#1

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Description updated (diff)
  • Status changed from Open to Feedback

What's and why wrong?

#2

Updated by pedz (Perry Smith) about 4 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.

#3

Updated by Hanmac (Hans Mackowiak) about 4 years ago

hm also the order is important:

"#{}#{foo}".encoding #=> US-ASCII
"#{foo}#{}".encoding #=> UTF-8

"#{}#{foo}".encoding != "#{foo}#{}".encoding #=> true

#4

Updated by nobu (Nobuyoshi Nakada) about 4 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]
#5

Updated by nagachika (Tomoyuki Chikanaga) about 4 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
#6

Updated by pedz (Perry Smith) about 4 years ago

Great! This is why I love the Ruby community.

Thank you!

#7

Updated by usa (Usaku NAKAMURA) about 4 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
#8

Updated by usa (Usaku NAKAMURA) about 4 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 4 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.

Also available in: Atom PDF