diff --git a/padrino-core/lib/padrino-core/application/routing.rb b/padrino-core/lib/padrino-core/application/routing.rb index 11a79f136..79cd908b2 100644 --- a/padrino-core/lib/padrino-core/application/routing.rb +++ b/padrino-core/lib/padrino-core/application/routing.rb @@ -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 diff --git a/padrino-core/test/test_routing.rb b/padrino-core/test/test_routing.rb index 11362474f..7b052a1f0 100644 --- a/padrino-core/test/test_routing.rb +++ b/padrino-core/test/test_routing.rb @@ -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" }