Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

raise ArgumentError, not TypeError for an invalid etag strength

  • Loading branch information...
commit 67159582cba6df215786c3557152a4d9d2faf1f8 1 parent 8d6a1b3
@rkh rkh authored
Showing with 12 additions and 2 deletions.
  1. +2 −2 lib/sinatra/base.rb
  2. +10 −0 test/helpers_test.rb
View
4 lib/sinatra/base.rb
@@ -288,8 +288,8 @@ def last_modified(time)
# When the current request includes an 'If-None-Match' header with a
# matching etag, execution is immediately halted. If the request method is
# GET or HEAD, a '304 Not Modified' response is sent.
- def etag(value, kind=:strong)
- raise TypeError, ":strong or :weak expected" if ![:strong,:weak].include?(kind)
+ def etag(value, kind = :strong)
+ raise ArgumentError, ":strong or :weak expected" unless [:strong,:weak].include?(kind)
value = '"%s"' % value
value = 'W/' + value if kind == :weak
response['ETag'] = value
View
10 test/helpers_test.rb
@@ -852,6 +852,16 @@ def obj.is_a?(thing) 60.is_a?(thing) end
get '/'
assert_equal 'W/"FOO"', response['ETag']
end
+
+ it 'raises an ArgumentError for an invalid strength' do
+ mock_app do
+ get '/' do
+ etag 'FOO', :w00t
+ "that's weak, dude."
+ end
+ end
+ assert_raise(ArgumentError) { get '/' }
+ end
end
describe 'back' do
Please sign in to comment.
Something went wrong with that request. Please try again.