rack 3.1.24 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rack might be problematic. Click here for more details.

@@ -17,7 +17,7 @@ module Rack
17
17
  # If +app+ is not specified, a Rack::Files of the same +root+ will be used.
18
18
 
19
19
  class Directory
20
- DIR_FILE = "<tr><td class='name'><a href='./%s'>%s</a></td><td class='size'>%s</td><td class='type'>%s</td><td class='mtime'>%s</td></tr>\n"
20
+ DIR_FILE = "<tr><td class='name'><a href='%s'>%s</a></td><td class='size'>%s</td><td class='type'>%s</td><td class='mtime'>%s</td></tr>\n"
21
21
  DIR_PAGE_HEADER = <<-PAGE
22
22
  <html><head>
23
23
  <title>%s</title>
@@ -51,7 +51,7 @@ table { width:100%%; }
51
51
  class DirectoryBody < Struct.new(:root, :path, :files)
52
52
  # Yield strings for each part of the directory entry
53
53
  def each
54
- show_path = Utils.escape_html(path.sub(/\A#{Regexp.escape(root)}/, ''))
54
+ show_path = Utils.escape_html(path.sub(/^#{root}/, ''))
55
55
  yield(DIR_PAGE_HEADER % [ show_path, show_path ])
56
56
 
57
57
  unless path.chomp('/') == root
@@ -82,7 +82,6 @@ table { width:100%%; }
82
82
  # Set the root directory and application for serving files.
83
83
  def initialize(root, app = nil)
84
84
  @root = ::File.expand_path(root)
85
- @root_with_separator = @root.end_with?(::File::SEPARATOR) ? @root : "#{@root}#{::File::SEPARATOR}"
86
85
  @app = app || Files.new(@root)
87
86
  @head = Head.new(method(:get))
88
87
  end
@@ -101,7 +100,6 @@ table { width:100%%; }
101
100
  if client_error_response = check_bad_request(path_info) || check_forbidden(path_info)
102
101
  client_error_response
103
102
  else
104
- path_info = Utils.clean_path_info(path_info)
105
103
  path = ::File.join(@root, path_info)
106
104
  list_path(env, path, path_info, script_name)
107
105
  end
@@ -120,9 +118,7 @@ table { width:100%%; }
120
118
  # Rack response to use for requests with paths outside the root, or nil if path is inside the root.
121
119
  def check_forbidden(path_info)
122
120
  return unless path_info.include? ".."
123
-
124
- expanded_path = ::File.expand_path(::File.join(@root, path_info))
125
- return if expanded_path == @root || expanded_path.start_with?(@root_with_separator)
121
+ return if ::File.expand_path(::File.join(@root, path_info)).start_with?(@root)
126
122
 
127
123
  body = "Forbidden\n"
128
124
  [403, { CONTENT_TYPE => "text/plain",
@@ -138,7 +134,7 @@ table { width:100%%; }
138
134
 
139
135
  # Globbing not safe as path could contain glob metacharacters
140
136
  body = DirectoryBody.new(@root, path, ->(basename) do
141
- stat = stat(basename == '..' ? ::File.dirname(path) : ::File.join(path, basename))
137
+ stat = stat(::File.join(path, basename))
142
138
  next unless stat
143
139
 
144
140
  url = ::File.join(*url_head + [Utils.escape_path(basename)])
data/lib/rack/files.rb CHANGED
@@ -194,7 +194,7 @@ EOF
194
194
  status,
195
195
  {
196
196
  CONTENT_TYPE => "text/plain",
197
- CONTENT_LENGTH => body.bytesize.to_s,
197
+ CONTENT_LENGTH => body.size.to_s,
198
198
  "x-cascade" => "pass"
199
199
  }.merge!(headers),
200
200
  [body]
data/lib/rack/head.rb CHANGED
@@ -15,9 +15,8 @@ module Rack
15
15
  _, _, body = response = @app.call(env)
16
16
 
17
17
  if env[REQUEST_METHOD] == HEAD
18
- response[2] = Rack::BodyProxy.new([]) do
19
- body.close if body.respond_to? :close
20
- end
18
+ body.close if body.respond_to?(:close)
19
+ response[2] = []
21
20
  end
22
21
 
23
22
  response