Emit a proper message when try_convert() fails.

This commit is contained in:
Akinori MUSHA 2013-04-16 01:38:05 +09:00
parent b02e800dfa
commit fcdaddcbe6

View file

@ -344,8 +344,8 @@ class HTTP::Cookie
# See #name. # See #name.
def name=(name) def name=(name)
name = String.try_convert(name) or name = (String.try_convert(name) or
raise TypeError, "#{name.class} is not a String" raise TypeError, "#{name.class} is not a String")
if name.empty? if name.empty?
raise ArgumentError, "cookie name cannot be empty" raise ArgumentError, "cookie name cannot be empty"
elsif name.match(/[\x00-\x20\x7F,;\\"=]/) elsif name.match(/[\x00-\x20\x7F,;\\"=]/)
@ -365,8 +365,8 @@ class HTTP::Cookie
self.expires = UNIX_EPOCH self.expires = UNIX_EPOCH
return @value = '' return @value = ''
end end
value = String.try_convert(value) or value = (String.try_convert(value) or
raise TypeError, "#{value.class} is not a String" raise TypeError, "#{value.class} is not a String")
if value.match(/[\x00-\x1F\x7F]/) if value.match(/[\x00-\x1F\x7F]/)
raise ArgumentError, "invalid cookie value" raise ArgumentError, "invalid cookie value"
end end
@ -393,8 +393,8 @@ class HTTP::Cookie
when DomainName when DomainName
@domain_name = domain @domain_name = domain
else else
domain = String.try_convert(domain) or domain = (String.try_convert(domain) or
raise TypeError, "#{domain.class} is not a String" raise TypeError, "#{domain.class} is not a String")
if domain.start_with?('.') if domain.start_with?('.')
for_domain = true for_domain = true
domain = domain[1..-1] domain = domain[1..-1]
@ -438,8 +438,8 @@ class HTTP::Cookie
# See #path. # See #path.
def path=(path) def path=(path)
path = String.try_convert(path) or path = (String.try_convert(path) or
raise TypeError, "#{path.class} is not a String" raise TypeError, "#{path.class} is not a String")
@path = path.start_with?('/') ? path : '/' @path = path.start_with?('/') ? path : '/'
end end