Skip to content

Commit

Permalink
Merge pull request #1378 from namusyaka/fix-broken-params
Browse files Browse the repository at this point in the history
Fix broken paramsб closes #1366
  • Loading branch information
ujifgc committed Aug 9, 2013
2 parents afcd820 + 14e2e3c commit a125bca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions padrino-core/lib/padrino-core/application/routing.rb
Expand Up @@ -124,6 +124,24 @@ def sort!
@routes.sort!{ |a, b| a.order <=> b.order }
end

class Node::SpanningRegex
def to_code
params_count = @ordered_indicies.size
whole_path_var = "whole_path#{root.next_counter}"
"#{whole_path_var} = request.joined_path
if match = #{@matcher.inspect}.match(#{whole_path_var}) and match.begin(0).zero?
_#{whole_path_var} = request.path.dup
" << param_capturing_code << "
remaining_path = #{whole_path_var}[match[0].size + (#{whole_path_var}[match[0].size] == ?/ ? 1 : 0), #{whole_path_var}.size]
request.path = remaining_path.split('/')
#{node_to_code}
request.path = _#{whole_path_var}
request.params.slice!(#{-params_count}, #{params_count})
end
"
end
end

#Monkey patching the Request class. Using Rack::Utils.unescape rather than
#URI.unescape which can't handle utf-8 chars
class Request
Expand Down
14 changes: 14 additions & 0 deletions padrino-core/test/test_routing.rb
Expand Up @@ -151,6 +151,20 @@ class FooError < RuntimeError; end
assert_equal 404, status
end

should "parse params when use regex for parts of a route" do
mock_app do
post :index, :with => [:foo, :bar], :bar => /.+/ do
"show #{params[:foo]}"
end

get :index, :map => '/mystuff/:a_id/boing/:boing_id' do
"show #{params[:a_id]} and #{params[:boing_id]}"
end
end
get "/mystuff/5/boing/2"
assert_equal "show 5 and 2", body
end

should "not generate overlapping head urls" do
app = mock_app do
get("/main"){ "hello" }
Expand Down

0 comments on commit a125bca

Please sign in to comment.