From 80b60671f7216c571ea8711d1de8ca824aefbe54 Mon Sep 17 00:00:00 2001 From: wycats Date: Mon, 17 May 2010 19:41:54 +0400 Subject: Revert "Moved encoding work in progress to a feature branch." This reverts commit ade756fe42423033bae8e5aea8f58782f7a6c517. --- railties/guides/source/getting_started.textile | 21 +++++++++++++++++++++ railties/lib/rails.rb | 1 + railties/lib/rails/application/configuration.rb | 10 +++++++++- railties/test/application/configuration_test.rb | 3 ++- 4 files changed, 33 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 5da7ff7daa..b7301bff20 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1462,11 +1462,32 @@ Rails also comes with built-in help that you can generate using the rake command * Running +rake doc:guides+ will put a full copy of the Rails Guides in the +doc/guides+ folder of your application. Open +doc/guides/index.html+ in your web browser to explore the Guides. * Running +rake doc:rails+ will put a full copy of the API documentation for Rails in the +doc/api+ folder of your application. Open +doc/api/index.html+ in your web browser to explore the API documentation. +h3. Configuration Gotchas + +The easiest way to work with Rails is to store all external data as UTF-8. If you don't, Ruby libraries and Rails will often be able to convert your native data into UTF-8, but this doesn't always work reliably, so you're better off ensuring that all external data is UTF-8. + +If you have made a mistake in this area, the most common symptom is a black diamond with a question mark inside appearing in the browser. Another common symptom is characters like "ü" appearing instead of "ü". Rails takes a number of internal steps to mitigate common causes of these problems that can be automatically detected and corrected. However, if you have external data that is not stored as UTF-8, it can occasionally result in these kinds of issues that cannot be automatically detected by Rails and corrected. + +Two very common sources of data that are not UTF-8: +* Your text editor: Most text editors (such as Textmate), default to saving files as + UTF-8. If your text editor does not, this can result in special characters that you + enter in your templates (such as é) to appear as a diamond with a question mark inside + in the browser. This also applies to your I18N translation files. + Most editors that do not already default to UTF-8 (such as some versions of + Dreamweaver) offer a way to change the default to UTF-8. Do so. +* Your database. Rails defaults to converting data from your database into UTF-8 at + the boundary. However, if your database is not using UTF-8 internally, it may not + be able to store all characters that your users enter. For instance, if your database + is using Latin-1 internally, and your user enters a Russian, Hebrew, or Japanese + character, the data will be lost forever once it enters the database. If possible, + use UTF-8 as the internal storage of your database. h3. Changelog "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2 +* May 16, 2010: Added a section on configuration gotchas to address common encoding + problems that people might have * April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com * April 25, 2010: Couple of more minor fixups "Mikel Lindsaar":credits:html#raasdnil * April 1, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 0611b2a9f5..be486ef2ac 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -23,6 +23,7 @@ if RUBY_VERSION < '1.9' $KCODE='u' else Encoding.default_external = Encoding::UTF_8 + Encoding.default_internal = Encoding::UTF_8 end module Rails diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 9353fbefef..8afe423973 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -1,4 +1,5 @@ require 'active_support/deprecation' +require 'active_support/core_ext/string/encoding' require 'rails/engine/configuration' module Rails @@ -27,8 +28,15 @@ module Rails def encoding=(value) @encoding = value - if defined?(Encoding) && Encoding.respond_to?(:default_external=) + if "ruby".encoding_aware? Encoding.default_external = value + Encoding.default_internal = value + else + $KCODE = value + if $KCODE == "NONE" + raise "The value you specified for config.encoding is " \ + "invalid. The possible values are UTF8, SJIS, or EUC" + end end end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index dfc4e2359b..c08bd2ef22 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -180,7 +180,8 @@ module ApplicationTests require "#{app_path}/config/application" unless RUBY_VERSION < '1.9' - assert_equal Encoding.find("utf-8"), Encoding.default_external + assert_equal Encoding::UTF_8, Encoding.default_external + assert_equal Encoding::UTF_8, Encoding.default_internal end end -- cgit v1.2.3 From 8c5e1652c7d1343a4b4acbc10bbcb59e202bf37d Mon Sep 17 00:00:00 2001 From: Rizwan Reza Date: Mon, 17 May 2010 01:55:56 +0430 Subject: Renames Array#rand -> Array#random_element Signed-off-by: Xavier Noria --- railties/test/application/initializers/frameworks_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 8e57022e5b..fadcc4c025 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -47,7 +47,7 @@ module ApplicationTests test "if there's no config.active_support.bare, all of ActiveSupport is required" do use_frameworks [] require "#{app_path}/config/environment" - assert_nothing_raised { [1,2,3].rand } + assert_nothing_raised { [1,2,3].random_element } end test "config.active_support.bare does not require all of ActiveSupport" do @@ -57,7 +57,7 @@ module ApplicationTests Dir.chdir("#{app_path}/app") do require "#{app_path}/config/environment" - assert_raises(NoMethodError) { [1,2,3].rand } + assert_raises(NoMethodError) { [1,2,3].random_element } end end -- cgit v1.2.3 From 25f7c030e4ea440ea6c2a84c92118299753392d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 18 May 2010 01:43:06 +0200 Subject: Simplify cookie_store by simply relying on cookies.signed. --- railties/lib/rails/application/configuration.rb | 8 ++------ railties/test/application/configuration_test.rb | 4 ++-- railties/test/application/middleware_test.rb | 5 ++++- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 8afe423973..1b8af370f7 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -11,7 +11,8 @@ module Rails :encoding, :consider_all_requests_local, :dependency_loading, :filter_parameters, :log_level, :logger, :metals, :plugins, :preload_frameworks, :reload_engines, :reload_plugins, - :secret_token, :serve_static_assets, :time_zone, :whiny_nils + :secret_token, :serve_static_assets, :session_options, + :time_zone, :whiny_nils def initialize(*) super @@ -138,11 +139,6 @@ module Rails end end - def session_options - return @session_options unless @session_store == :cookie_store - @session_options.merge(:secret => @secret_token) - end - protected def default_middleware_stack diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index c08bd2ef22..9928ee2c52 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -196,7 +196,7 @@ module ApplicationTests test "config.secret_token is sent in env" do make_basic_app do |app| - app.config.secret_token = 'ThisIsASECRET123' + app.config.secret_token = 'b3c631c314c0bbca50c1b2843150fe33' app.config.session_store :disabled end @@ -208,7 +208,7 @@ module ApplicationTests end get "/" - assert_equal 'ThisIsASECRET123', last_response.body + assert_equal 'b3c631c314c0bbca50c1b2843150fe33', last_response.body end test "protect from forgery is the default in a new app" do diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index d08f04bddb..617525bf78 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -175,7 +175,10 @@ module ApplicationTests def remote_ip(env = {}) remote_ip = nil - env = Rack::MockRequest.env_for("/").merge(env).merge('action_dispatch.show_exceptions' => false) + env = Rack::MockRequest.env_for("/").merge(env).merge!( + 'action_dispatch.show_exceptions' => false, + 'action_dispatch.secret_token' => 'b3c631c314c0bbca50c1b2843150fe33' + ) endpoint = Proc.new do |e| remote_ip = ActionDispatch::Request.new(e).remote_ip -- cgit v1.2.3 From 0c3cde404ac45d59439c324a4a13ec239c582a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 18 May 2010 02:07:59 +0200 Subject: Kill legacy dispatcher. --- railties/lib/rails/dispatcher.rb | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 railties/lib/rails/dispatcher.rb (limited to 'railties') diff --git a/railties/lib/rails/dispatcher.rb b/railties/lib/rails/dispatcher.rb deleted file mode 100644 index 75ee4de140..0000000000 --- a/railties/lib/rails/dispatcher.rb +++ /dev/null @@ -1,24 +0,0 @@ -#-- -# Copyright (c) 2004-2010 David Heinemeier Hansson -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -#++ -require 'action_controller/deprecated/dispatcher' -Dispatcher = ActionController::Dispatcher -- cgit v1.2.3 From 39a246f545a714b21c669e2f6eda4012526c3874 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 19 May 2010 15:14:51 -0400 Subject: Final iteration of use better testing methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#4652 state:resolved] Signed-off-by: José Valim --- railties/test/application/rackup_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/application/rackup_test.rb b/railties/test/application/rackup_test.rb index f909c1b282..3790de721c 100644 --- a/railties/test/application/rackup_test.rb +++ b/railties/test/application/rackup_test.rb @@ -28,14 +28,14 @@ module ApplicationTests test "Rails.application is available after config.ru has been racked up" do rackup - assert Rails.application.is_a?(Rails::Application) + assert_kind_of Rails::Application, Rails.application end # Passenger still uses AC::Dispatcher, so we need to # keep it working for now test "deprecated ActionController::Dispatcher still works" do rackup - assert ActionController::Dispatcher.new.is_a?(Rails::Application) + assert_kind_of? Rails::Application, ActionController::Dispatcher.new end test "the config object is available on the application object" do -- cgit v1.2.3