mirror of
https://github.com/ruby/ruby.git
synced 2025-08-27 06:56:13 +02:00
Use filesystem encoding as FileHandler's encoding
instead of `@root.encoding`. And fallback to ASCII-8BIT when filesystem encoding is US-ASCII. When `@root.encoding` is not compatible filesystem encoding, `Encoding::CompatibilityError` raised at `webrick/httpservlet/filehandler.rb:341`. So `DocumentRoot` must be compatible with filesystem encoding.
This commit is contained in:
parent
78d4eace02
commit
97c1782db6
2 changed files with 14 additions and 10 deletions
|
@ -212,6 +212,14 @@ module WEBrick
|
|||
|
||||
# :stopdoc:
|
||||
|
||||
def set_filesystem_encoding(str)
|
||||
if Encoding.find('filesystem') == Encoding::US_ASCII
|
||||
str.b
|
||||
else
|
||||
str.dup.force_encoding('filesystem')
|
||||
end
|
||||
end
|
||||
|
||||
def service(req, res)
|
||||
# if this class is mounted on "/" and /~username is requested.
|
||||
# we're going to override path information before invoking service.
|
||||
|
@ -325,16 +333,7 @@ module WEBrick
|
|||
|
||||
def set_filename(req, res)
|
||||
res.filename = @root
|
||||
path_info = req.path_info.scan(%r|/[^/]*|)
|
||||
begin
|
||||
path_info.map! do |path|
|
||||
path.force_encoding('filesystem').encode(@root.encoding)
|
||||
end
|
||||
rescue EncodingError
|
||||
path_info.map! do |path|
|
||||
path.force_encoding(@root.encoding)
|
||||
end
|
||||
end
|
||||
path_info = set_filesystem_encoding(req.path_info).scan(%r|/[^/]*|)
|
||||
|
||||
path_info.unshift("") # dummy for checking @root dir
|
||||
while base = path_info.first
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue