diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 10 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 5 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 4 |
6 files changed, 28 insertions, 4 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 8c2d887cb3..345b5aa330 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,15 @@ ## Rails 4.0.0 (unreleased) ## +* Support unicode characters in routes. Route will be automatically escaped, so instead of manually escaping: + + get Rack::Utils.escape('こんにちは') => 'home#index' + + You just have to write the unicode route: + + get 'こんにちは' => 'home#index' + + *kennyj* + * Return proper format on exceptions. *Santiago Pastorino* * Allow to use mounted_helpers (helpers for accessing mounted engines) in ActionView::TestCase. *Piotr Sarnacki* diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb index 38a0270151..29090882a5 100644 --- a/actionpack/lib/action_dispatch/routing.rb +++ b/actionpack/lib/action_dispatch/routing.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 require 'active_support/core_ext/object/to_param' require 'active_support/core_ext/regexp' @@ -218,6 +219,12 @@ module ActionDispatch # # match "/stories" => redirect("/posts") # + # == Unicode character routes + # + # You can specify unicode character routes in your router: + # + # match "こんにちは" => "welcome#index" + # # == Routing to Rack Applications # # Instead of a String, like <tt>posts#index</tt>, which corresponds to the diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 25d099d83e..94242ad962 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1387,7 +1387,7 @@ module ActionDispatch options[:as] = name_for_action(options[:as], action) end - mapping = Mapping.new(@set, @scope, path, options) + mapping = Mapping.new(@set, @scope, URI.parser.escape(path), options) app, conditions, requirements, defaults, as, anchor = mapping.to_route @set.add_route(app, conditions, requirements, defaults, as, anchor) end diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb index 3823f87027..03dfa110e3 100644 --- a/actionpack/lib/action_view.rb +++ b/actionpack/lib/action_view.rb @@ -36,7 +36,7 @@ module ActionView autoload :LookupContext autoload :PathSet autoload :Template - autoload :TestCase + autoload_under "renderer" do autoload :Renderer @@ -73,6 +73,8 @@ module ActionView end end + autoload :TestCase + ENCODING_FLAG = '#.*coding[:=]\s*(\S+)[ \t]*' end diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 306b8a93da..6cc1370105 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -1760,6 +1760,7 @@ class RackMountIntegrationTests < ActiveSupport::TestCase get 'account(/:action)' => "account#subscription" get 'pages/:page_id/:controller(/:action(/:id))' get ':controller/ping', :action => 'ping' + get 'こんにちは/世界', :controller => 'news', :action => 'index' match ':controller(/:action(/:id))(.:format)', :via => :all root :to => "news#index" } @@ -1876,6 +1877,10 @@ class RackMountIntegrationTests < ActiveSupport::TestCase assert_equal({:controller => 'people', :action => 'create', :person => { :name => 'Josh'}}, params) end + def test_unicode_path + assert_equal({:controller => 'news', :action => 'index'}, @routes.recognize_path(URI.parser.escape('こんにちは/世界'), :method => :get)) + end + private def sort_extras!(extras) if extras.length == 2 diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index fa4cb301eb..f15dd7214b 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2472,7 +2472,7 @@ end class TestUnicodePaths < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| app.draw do - get "/#{Rack::Utils.escape("ほげ")}" => lambda { |env| + get "/ほげ" => lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] }, :as => :unicode_path end @@ -2727,4 +2727,4 @@ class TestInvalidUrls < ActionDispatch::IntegrationTest assert_response :bad_request end end -end
\ No newline at end of file +end |