lib/rack/utils.rb in rack-1.3.6 vs lib/rack/utils.rb in rack-1.3.7
- old
+ new
@@ -3,15 +3,18 @@
require 'set'
require 'tempfile'
require 'rack/multipart'
major, minor, patch = RUBY_VERSION.split('.').map { |v| v.to_i }
+ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
if major == 1 && minor < 9
require 'rack/backports/uri/common_18'
-elsif major == 1 && minor == 9 && patch < 3
+elsif major == 1 && minor == 9 && patch == 2 && RUBY_PATCHLEVEL <= 320 && RUBY_ENGINE != 'jruby'
require 'rack/backports/uri/common_192'
+elsif major == 1 && minor == 9 && patch == 3 && RUBY_PATCHLEVEL < 125
+ require 'rack/backports/uri/common_193'
else
require 'uri/common'
end
module Rack
@@ -58,10 +61,11 @@
max_key_space = Utils.key_space_limit
bytes = 0
(qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
+ next if p.empty?
k, v = p.split('=', 2).map { |x| unescape(x) }
if k
bytes += k.size
if bytes > max_key_space
@@ -313,19 +317,19 @@
# Returns nil if the header is missing or syntactically invalid.
# Returns an empty array if none of the ranges are satisfiable.
def byte_ranges(env, size)
# See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35>
http_range = env['HTTP_RANGE']
- return nil unless http_range
+ return nil unless http_range && http_range =~ /bytes=([^;]+)/
ranges = []
- http_range.split(/,\s*/).each do |range_spec|
- matches = range_spec.match(/bytes=(\d*)-(\d*)/)
- return nil unless matches
- r0,r1 = matches[1], matches[2]
+ $1.split(/,\s*/).each do |range_spec|
+ return nil unless range_spec =~ /(\d*)-(\d*)/
+ r0,r1 = $1, $2
if r0.empty?
return nil if r1.empty?
# suffix-byte-range-spec, represents trailing suffix of file
- r0 = [size - r1.to_i, 0].max
+ r0 = size - r1.to_i
+ r0 = 0 if r0 < 0
r1 = size - 1
else
r0 = r0.to_i
if r1.empty?
r1 = size - 1