Project

General

Profile

Actions

Bug #11519

closed

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

Added by pedz (Perry Smith) over 8 years ago. Updated over 8 years ago.

Status:
Closed
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.

Actions #1

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

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

What's and why wrong?

Actions #2

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

Actions #3

Updated by Hanmac (Hans Mackowiak) over 8 years ago

hm also the order is important:

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

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

Actions #4

Updated by nobu (Nobuyoshi Nakada) over 8 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]
Actions #5

Updated by nagachika (Tomoyuki Chikanaga) over 8 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
Actions #6

Updated by pedz (Perry Smith) over 8 years ago

Great! This is why I love the Ruby community.

Thank you!

Actions #7

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

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0