diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-12-29 12:50:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-29 12:50:36 -0500 |
commit | c491bf012948383632e53f874c552041a6e23b36 (patch) | |
tree | dfd008a1de576b048fc2a207400f7062ef409349 | |
parent | 415e17d0b54681545d36a0f43d4cd8761de77bee (diff) | |
parent | 0713265fd15f5ce0d6e86e620a2de254ff291f81 (diff) | |
download | rails-c491bf012948383632e53f874c552041a6e23b36.tar.gz rails-c491bf012948383632e53f874c552041a6e23b36.tar.bz2 rails-c491bf012948383632e53f874c552041a6e23b36.zip |
Merge pull request #27499 from maclover7/jm-fix-27454
Use `next` instead of `break`; avoid terminating whole loop
-rw-r--r-- | actionpack/lib/action_dispatch/journey/formatter.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/url_for_test.rb | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index 1d239addf8..f3b8e82d32 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -36,7 +36,7 @@ module ActionDispatch route.parts.reverse_each do |key| break if defaults[key].nil? && parameterized_parts[key].present? - break if parameterized_parts[key].to_s != defaults[key].to_s + next if parameterized_parts[key].to_s != defaults[key].to_s break if required_parts.include?(key) parameterized_parts.delete(key) diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index 4b6f33c545..382b4e273d 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -487,6 +487,27 @@ module AbstractController end end + def test_default_params_first_empty + with_routing do |set| + set.draw do + get "(:param1)/test(/:param2)" => "index#index", + defaults: { + param1: 1, + param2: 2 + }, + constraints: { + param1: /\d*/, + param2: /\d+/ + } + end + + kls = Class.new { include set.url_helpers } + kls.default_url_options[:host] = "www.basecamphq.com" + + assert_equal "http://www.basecamphq.com/test", kls.new.url_for(controller: "index", param1: "1") + end + end + private def extract_params(url) url.split("?", 2).last.split("&").sort |