1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

fixed escaped paths not resolving static files [Matthew Walker]

Signed-off-by: Blake Mizerany <blakemizerany@blake.local>
This commit is contained in:
Blake Mizerany 2008-04-26 15:09:40 -07:00
parent 9c875ffda0
commit d16ee6533b
2 changed files with 13 additions and 5 deletions

View file

@ -5,9 +5,9 @@ end
require 'rack' require 'rack'
require 'rubygems' require 'rubygems'
require 'uri'
require 'time' require 'time'
require 'ostruct' require 'ostruct'
require "uri"
if ENV['SWIFT'] if ENV['SWIFT']
require 'swiftcore/swiftiplied_mongrel' require 'swiftcore/swiftiplied_mongrel'
@ -217,14 +217,14 @@ module Sinatra
def invoke(request) def invoke(request)
return unless File.file?( return unless File.file?(
Sinatra.application.options.public + request.path_info Sinatra.application.options.public + request.path_info.http_unescape
) )
Result.new(block, {}, 200) Result.new(block, {}, 200)
end end
def block def block
Proc.new do Proc.new do
send_file Sinatra.application.options.public + request.path_info, send_file Sinatra.application.options.public + request.path_info.http_unescape,
:disposition => nil :disposition => nil
end end
end end
@ -1174,14 +1174,16 @@ class String
# Converts +self+ to an escaped URI parameter value # Converts +self+ to an escaped URI parameter value
# 'Foo Bar'.to_param # => 'Foo%20Bar' # 'Foo Bar'.to_param # => 'Foo%20Bar'
def to_param def to_param
URI.escape(self) Rack::Utils.escape(self)
end end
alias :http_escape :to_param
# Converts +self+ from an escaped URI parameter value # Converts +self+ from an escaped URI parameter value
# 'Foo%20Bar'.from_param # => 'Foo Bar' # 'Foo%20Bar'.from_param # => 'Foo Bar'
def from_param def from_param
URI.unescape(self) Rack::Utils.unescape(self)
end end
alias :http_unescape :from_param
end end

View file

@ -77,6 +77,12 @@ context "Static files (by default)" do
headers['Content-Transfer-Encoding'].should.be.nil headers['Content-Transfer-Encoding'].should.be.nil
end end
specify "should be served even if their path is url escaped" do
get_it('/fo%6f.xml')
should.be.ok
body.should.equal "<foo></foo>\n"
end
end end
context "SendData" do context "SendData" do