rack 3.1.21 → 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
@@ -119,9 +118,7 @@ table { width:100%%; }
119
118
  # Rack response to use for requests with paths outside the root, or nil if path is inside the root.
120
119
  def check_forbidden(path_info)
121
120
  return unless path_info.include? ".."
122
-
123
- expanded_path = ::File.expand_path(::File.join(@root, path_info))
124
- 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)
125
122
 
126
123
  body = "Forbidden\n"
127
124
  [403, { CONTENT_TYPE => "text/plain",
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