Skip to content

Commit

Permalink
Merge pull request #1288 from Ortuna/http-router-fix-unicode
Browse files Browse the repository at this point in the history
Http router fix unicode
  • Loading branch information
Darío Javier Cravero committed May 15, 2013
2 parents d146158 + 6894ed0 commit 2ba94a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions padrino-core/lib/padrino-core/application/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ def significant_variable_names
end
end

#Monkey patching the Request class. Using Rack::Utils.unescape rather than
#URI.unescape which can't handle utf-8 chars
class Request
def initialize(path, rack_request)
@rack_request = rack_request
@path = Rack::Utils.unescape(path).split(/\//)
@path.shift if @path.first == ''
@path.push('') if path[-1] == ?/
@extra_env = {}
@params = []
@acceptable_methods = Set.new
end
end

class Node::Path
def to_code
path_ivar = inject_root_ivar(self)
Expand Down
9 changes: 9 additions & 0 deletions padrino-core/test/test_routing.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#encoding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/helper')

class FooError < RuntimeError; end
Expand Down Expand Up @@ -100,6 +101,14 @@ class FooError < RuntimeError; end
assert_equal "no access", body
end

should 'parse routes that are encoded' do
mock_app do
get('/щч') { 'success!' }
end
get(URI.escape('/щч'))
assert_equal 'success!', body
end

should 'match correctly similar paths' do
mock_app do
get("/my/:foo_id"){ params[:foo_id] }
Expand Down

0 comments on commit 2ba94a2

Please sign in to comment.