Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make sure regexp chunks are grouped when the segment has a regexp con…
…straint so that captures are counted correctly (closes #5267)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4434 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jamis committed Jun 5, 2006
1 parent 7d88146 commit 332fcfa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/routing.rb
Expand Up @@ -489,7 +489,7 @@ def value_regexp
Regexp.new "\\A#{regexp.source}\\Z" if regexp
end
def regexp_chunk
regexp ? regexp.source : "([^#{Routing::SEPARATORS.join}]+)"
regexp ? "(#{regexp.source})" : "([^#{Routing::SEPARATORS.join}]+)"
end

def build_pattern(pattern)
Expand Down
23 changes: 23 additions & 0 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -1230,6 +1230,29 @@ def test_recognize_with_conditions
ensure
Object.send(:remove_const, :PeopleController)
end

def test_typo_recognition
Object.const_set(:ArticlesController, Class.new)

set.draw do |map|
map.connect 'articles/:year/:month/:day/:title',
:controller => 'articles', :action => 'permalink',
:year => /\d{4}/, :day => /\d{1,2}/, :month => /\d{1,2}/
end

request.path = "/articles/2005/11/05/a-very-interesting-article"
request.method = :get
assert_nothing_raised { set.recognize(request) }
assert_equal("permalink", request.path_parameters[:action])
assert_equal("2005", request.path_parameters[:year])
assert_equal("11", request.path_parameters[:month])
assert_equal("05", request.path_parameters[:day])
assert_equal("a-very-interesting-article", request.path_parameters[:title])

ensure
Object.send(:remove_const, :ArticlesController)
end


def test_recognize_with_conditions_and_format
Object.const_set(:PeopleController, Class.new)
Expand Down

0 comments on commit 332fcfa

Please sign in to comment.