Skip to content

Commit

Permalink
fix HEADER_VALUE_WITH_PARAMS regex and added a test case for this regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciomacadden committed Mar 14, 2013
1 parent 54d6ba0 commit 05c16d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Sinatra
# http://rack.rubyforge.org/doc/classes/Rack/Request.html
class Request < Rack::Request
HEADER_PARAM = /\s*[\w.]+=(?:[\w.]+|"(?:[^"\\]|\\.)*")?\s*/
HEADER_VALUE_WITH_PARAMS = /(?:(?:\w+|\*)\/(?:\w+|\*))\s*(?:;#{HEADER_PARAM})*/
HEADER_VALUE_WITH_PARAMS = /(?:(?:\w+|\*)\/(?:\w+\-*\w+|\*))\s*(?:;#{HEADER_PARAM})*/

# Returns an array of acceptable media types for the response
def accept
Expand Down
10 changes: 10 additions & 0 deletions test/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,9 @@ class RoutingTest < Test::Unit::TestCase
get '/foo', :provides => :html do
env['HTTP_ACCEPT']
end
get '/stream', :provides => 'text/event-stream' do
env['HTTP_ACCEPT']
end
}

get '/', {}, { 'HTTP_ACCEPT' => 'application/xml' }
Expand All @@ -792,6 +795,13 @@ class RoutingTest < Test::Unit::TestCase

get '/foo', {}, { 'HTTP_ACCEPT' => '' }
assert !ok?

get '/stream', {}, { 'HTTP_ACCEPT' => 'text/event-stream' }
assert ok?
assert_equal 'text/event-stream', body

get '/stream', {}, { 'HTTP_ACCEPT' => '' }
assert !ok?
end

it "filters by current Content-Type" do
Expand Down

0 comments on commit 05c16d5

Please sign in to comment.