From 44ab0902e36e61d2fc9ef92810a908d1d01b1fd6 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Sun, 10 Oct 2010 13:41:56 +0200 Subject: [PATCH] Avoid relying on $1 for setting Content-Range header, as its value might be lost. Makes test pass. --- lib/sinatra/base.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index eafba2da..adaac09d 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -162,12 +162,12 @@ module Sinatra response['Content-Disposition'] = 'inline' end sf = StaticFile.open(path, 'rb') - if (env['HTTP_RANGE'] =~ /^bytes=(\d+-\d+(?:,\d+-\d+)*)$/) - sf.ranges = $1.split(',').collect{|range| range.split('-').collect{|n| n.to_i}} + if m = /^bytes=(\d+-\d+(?:,\d+-\d+)*)$/.match(env['HTTP_RANGE']) + sf.ranges = m[1].split(',').collect{|range| range.split('-').collect{|n| n.to_i}} sf.ranges.each do |range| halt 416 if range[1] < range[0] end - response['Content-Range'] = "bytes #{$1}/#{response['Content-Length']}" + response['Content-Range'] = "bytes #{m[1]}/#{response['Content-Length']}" response['Content-Length'] = sf.ranges.dup.inject(0){|total,range| total + range[1] - range[0] + 1 }.to_s halt 206, sf else