提交 0a0b5bd7 编写于 作者: J Jamis Buck

fix to ';' interpretation in route recognition--only follow a route with ';'...

fix to ';' interpretation in route recognition--only follow a route with ';' if the segment in question actually contains a ';'


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4244 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 010a10f3
......@@ -78,10 +78,11 @@ def initialize(parts, *args)
def write_recognition(g)
raise RoutingError, "Subpath components must occur last" unless g.after.empty?
g.next_segment
g.line "subindex, subpath = 0, #{g.next_segment}.split(/;/)"
tweak_recognizer(g).go
g.move_forward { |gg| gg.continue }
g.if("#{g.next_segment(true)} && #{g.next_segment}.include?(';')") do |gp|
gp.line "subindex, subpath = 0, #{gp.next_segment}.split(/;/)"
tweak_recognizer(gp).go
gp.move_forward { |gpp| gpp.continue }
end
end
def write_generation(g)
......
......@@ -1003,22 +1003,27 @@ def test_subpath_recognized
Object.const_set(:SubpathBooksController, Class.new(ActionController::Base))
rs.draw do |r|
r.connect '/books/:id;edit', :controller => 'subpath_books', :action => 'edit'
r.connect '/items/:id;:action', :controller => 'subpath_books'
#r.connect '/books/:id;edit', :controller => 'subpath_books', :action => 'edit'
#r.connect '/items/:id;:action', :controller => 'subpath_books'
r.connect '/posts/new;:action', :controller => 'subpath_books'
r.connect '/posts/:id', :controller => 'subpath_books', :action => "show"
end
hash = rs.recognize_path %w(books 17;edit)
assert_not_nil hash
assert_equal %w(subpath_books 17 edit), [hash["controller"].controller_name, hash["id"], hash["action"]]
hash = rs.recognize_path %w(items 3;complete)
assert_not_nil hash
assert_equal %w(subpath_books 3 complete), [hash["controller"].controller_name, hash["id"], hash["action"]]
hash = rs.recognize_path %w(posts new;preview)
# hash = rs.recognize_path %w(books 17;edit)
# assert_not_nil hash
# assert_equal %w(subpath_books 17 edit), [hash["controller"].controller_name, hash["id"], hash["action"]]
#
# hash = rs.recognize_path %w(items 3;complete)
# assert_not_nil hash
# assert_equal %w(subpath_books 3 complete), [hash["controller"].controller_name, hash["id"], hash["action"]]
#
# hash = rs.recognize_path %w(posts new;preview)
# assert_not_nil hash
# assert_equal %w(subpath_books preview), [hash["controller"].controller_name, hash["action"]]
hash = rs.recognize_path %w(posts 7)
assert_not_nil hash
assert_equal %w(subpath_books preview), [hash["controller"].controller_name, hash["action"]]
assert_equal %w(subpath_books show 7), [hash["controller"].controller_name, hash["action"], hash["id"]]
# for now, low-hanging fruit only. We don't allow subpath components anywhere
# except at the end of the path
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册