This project is archived and is in readonly mode.

#6430 ✓invalid
Yvan BARTHÉLEMY

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

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

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

Comments and changes to this ticket

  • Santiago Pastorino

    Santiago Pastorino February 14th, 2011 @ 09:09 PM

    • 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

  • klkk

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages