Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Rails.root string conversion gives an ASCII string on Ruby 1.9.2

#6430

Here is a failing test file on Rails 3.0.3

#encoding: UTF-8
require 'test_helper'

class RootTest < ActionDispatch::IntegrationTest
  fixtures :all

  # Replace this with your real tests.
  test "Rails.root encoding is UTF-8" do
    assert_equal "UTF-8", "#{Rails.root}".encoding.name
  end

  test "Dummy encoding is UTF-8" do
    assert_equal "UTF-8", "#{"toto"}".encoding.name
  end
end

Reported by Yvan BARTHÉLEMY · February 14th, 2011 @ 05:24 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to invalid
    • Importance changed from to Low

    This is not a Rails thing.
    Try the following

    ➜  cat santiago.rb 
    module Santiago
      def name
        'Santiago'
      end
    end
    ➜  /tmp  cat app.rb
    #encoding: UTF-8
    
    require 'santiago'
    
    puts "#{Santiago.name}".encoding.name
    ➜  /tmp  ruby -I. test2.rb
    "US-ASCII"
    

    Ruby encodes the string to match the magic comment when you define literal strings

    February 14th, 2011 @ 09:09 PM