Permalink
Browse files

Merge pull request #1378 from namusyaka/fix-broken-params

Fix broken paramsб closes #1366
  • Loading branch information...
ujifgc committed Aug 9, 2013
2 parents afcd820 + 14e2e3c commit a125bcac2b51b820bb8b27b13dd2a111d5504c8a
Showing with 32 additions and 0 deletions.
  1. +18 −0 padrino-core/lib/padrino-core/application/routing.rb
  2. +14 −0 padrino-core/test/test_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
@@ -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" }

0 comments on commit a125bca

Please sign in to comment.