aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorTatiana Soukiassian <binaryberry@gmail.com>2014-12-13 15:34:41 +0000
committerTatiana Soukiassian <binaryberry@gmail.com>2014-12-13 15:42:15 +0000
commit1a50be823186082e8b5a29d8e9ea3a289318d9c1 (patch)
tree364f24c8e612f63d6ca1739a38353ff9f1d23455 /actionpack
parent9688270d3e0994ce57de0adbc72b3ab4faaf2c32 (diff)
downloadrails-1a50be823186082e8b5a29d8e9ea3a289318d9c1.tar.gz
rails-1a50be823186082e8b5a29d8e9ea3a289318d9c1.tar.bz2
rails-1a50be823186082e8b5a29d8e9ea3a289318d9c1.zip
Fix handling of positional url helper arguments when format is false
There is no need to subtract one from the path_params size when there is no format parameter because it is not present in the path_params array. Fixes #17819.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md6
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb10
-rw-r--r--actionpack/test/dispatch/routing_test.rb28
3 files changed, 42 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 556545c0d8..b68f2a28fe 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1 +1,7 @@
+* Fixed handling of positional url helper arguments when `format: false`.
+
+ Fixes #17819.
+
+ *Andrew White*, *Tatiana Soukiassian*
+
Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/actionpack/CHANGELOG.md) for previous changes.
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index f3144dc2d3..34cd06fd58 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -280,9 +280,15 @@ module ActionDispatch
end
def handle_positional_args(controller_options, inner_options, args, result, path_params)
-
if args.size > 0
- if args.size < path_params.size - 1 # take format into account
+ # take format into account
+ if path_params.include?(:format)
+ path_params_size = path_params.size - 1
+ else
+ path_params_size = path_params.size
+ end
+
+ if args.size < path_params_size
path_params -= controller_options.keys
path_params -= result.keys
end
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index d0a624784a..aae95fb355 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -4433,3 +4433,31 @@ class TestUrlGenerationErrors < ActionDispatch::IntegrationTest
assert_equal message, error.message
end
end
+
+class TestDefaultUrlOptions < ActionDispatch::IntegrationTest
+ class PostsController < ActionController::Base
+ def archive
+ render :text => "posts#archive"
+ end
+ end
+
+ Routes = ActionDispatch::Routing::RouteSet.new
+ Routes.draw do
+ default_url_options locale: 'en'
+ scope ':locale', format: false do
+ get '/posts/:year/:month/:day', to: 'posts#archive', as: 'archived_posts'
+ end
+ end
+
+ APP = build_app Routes
+
+ def app
+ APP
+ end
+
+ include Routes.url_helpers
+
+ def test_positional_args_with_format_false
+ assert_equal '/en/posts/2014/12/13', archived_posts_path(2014, 12, 13)
+ end
+end