Ignore incompatible YAML data.

This commit is contained in:
Akinori MUSHA 2013-03-15 10:25:31 +09:00
parent f7bb9d6272
commit 5cebc4e56d
2 changed files with 23 additions and 11 deletions

View file

@ -111,19 +111,24 @@ equivalent using `HTTP::Cookie`:
# after
jar.save(file)
`HTTP::Cookie` and `CookieJar` raises runtime errors to help
migration, so try running your test code once to find out how to fix
your code base.
`HTTP::Cookie`/`CookieJar` raise runtime errors to help migration, so
after replacing the class names, try running your test code once to
find out how to fix your code base.
The YAML serialization format has changed. Loading YAML files
generated by `Mechanize::CookieJar#save_as` will not raise an
exception, but the content is simply ignored. Note that there is
(obviously) no forward compatibillity in the YAML serialization.
### File formats
The YAML serialization format has changed, and `HTTP::CookieJar#load`
cannot import what is written in a YAML file saved by
`Mechanize::CookieJar#save_as`. `HTTP::CookieJar#load` will not raise
an exception if an incompatible YAML file is given, but the content is
silently ignored.
Note that there is (obviously) no forward compatibillity with this.
Trying to load a YAML file saved by `HTTP::CookieJar` with
`Mechanize::CookieJar` will fail in `ArgumentError`.
`Mechanize::CookieJar` will fail in runtime error.
On the other hand, there has been (and will ever be) no change in the
cookies.txt format.
cookies.txt format, so use it instead if compatibility is required.
## Contributing

View file

@ -13,11 +13,18 @@ class HTTP::CookieJar::YAMLSaver < HTTP::CookieJar::AbstractSaver
def load(io, jar)
begin
YAML.load(io)
data = YAML.load(io)
rescue ArgumentError
@logger.warn "unloadable YAML cookie data discarded" if @logger
return
end
unless data.instance_of?(Array)
@logger.warn "incompatible YAML cookie data discarded" if @logger
return
end.each { |cookie|
end
data.each { |cookie|
jar.add(cookie)
}
end