mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-03-25 08:55:53 +00:00
Cookie#new: Reject a mixed case symbol as keyword for simplicity.
This fixes error with Ruby 1.8.
This commit is contained in:
parent
20cb22bbb0
commit
04950f6796
2 changed files with 14 additions and 21 deletions
|
|
@ -111,15 +111,11 @@ class HTTP::Cookie
|
|||
# new(**attr_hash)
|
||||
#
|
||||
# Creates a cookie object. For each key of `attr_hash`, the setter
|
||||
# is called if defined. Each key can be either a symbol or a
|
||||
# string of downcased attribute names.
|
||||
#
|
||||
# This method accepts any attribute name for which a setter method
|
||||
# is defined. Beware, however, any error (typically ArgumentError)
|
||||
# a setter method raises will be passed through. It is preferred
|
||||
# that each keyword is a downcased symbol. Support for strings and
|
||||
# mixed case keywords will be obsoleted when ruby 2.0 keyword syntax
|
||||
# is adopted.
|
||||
# is called if defined and any error (typically ArgumentError or
|
||||
# TypeError) that is raised will be passed through. Each key can be
|
||||
# either a downcased symbol or a string that may be mixed case.
|
||||
# Support for the latter may, however, be obsoleted in future when
|
||||
# Ruby 2.0's keyword syntax is adopted.
|
||||
#
|
||||
# If `value` is omitted or it is nil, an expiration cookie is
|
||||
# created unless `max_age` or `expires` (`expires_at`) is given.
|
||||
|
|
@ -183,20 +179,17 @@ class HTTP::Cookie
|
|||
@httponly = val
|
||||
when :secure, :secure?
|
||||
@secure = val
|
||||
when /[A-Z]/
|
||||
warn "keyword should be downcased: #{okey.inspect}" if $VERBOSE
|
||||
key = key.downcase
|
||||
redo
|
||||
when Symbol
|
||||
setter = :"#{key}="
|
||||
if respond_to?(setter)
|
||||
__send__(setter, val)
|
||||
else
|
||||
warn "unknown keyword: #{okey.inspect}" if $VERBOSE
|
||||
warn "unknown attribute name: #{okey.inspect}" if $VERBOSE
|
||||
next
|
||||
end
|
||||
when String
|
||||
warn "use symbol for keyword: #{okey.inspect}" if $VERBOSE
|
||||
key = key.to_sym
|
||||
warn "use downcased symbol for keyword: #{okey.inspect}" if $VERBOSE
|
||||
key = key.downcase.to_sym
|
||||
redo
|
||||
else
|
||||
warn "invalid keyword ignored: #{okey.inspect}" if $VERBOSE
|
||||
|
|
|
|||
|
|
@ -528,25 +528,25 @@ class TestHTTPCookie < Test::Unit::TestCase
|
|||
|
||||
# various keywords
|
||||
[
|
||||
[:Expires, /should be downcased/],
|
||||
["Expires", /should be downcased.*use symbol/m],
|
||||
["Expires", /use downcased symbol/],
|
||||
].each { |key, pattern|
|
||||
assert_warning(pattern, "warn of key: #{key.inspect}") {
|
||||
cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', key => expires.dup)
|
||||
assert_equal 'key', cookie.name
|
||||
assert_equal 'value', cookie.value
|
||||
assert_equal expires, cookie.expires
|
||||
assert_equal expires, cookie.expires, "key: #{key.inspect}"
|
||||
}
|
||||
}
|
||||
[
|
||||
[:expires?, /unknown keyword/],
|
||||
[:Expires, /unknown attribute name/],
|
||||
[:expires?, /unknown attribute name/],
|
||||
[[:expires], /invalid keyword/],
|
||||
].each { |key, pattern|
|
||||
assert_warning(pattern, "warn of key: #{key.inspect}") {
|
||||
cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', key => expires.dup)
|
||||
assert_equal 'key', cookie.name
|
||||
assert_equal 'value', cookie.value
|
||||
assert_equal nil, cookie.expires
|
||||
assert_equal nil, cookie.expires, "key: #{key.inspect}"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue