Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/http/cookie_jar/yaml_saver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def save(io, jar)

def load(io, jar)
begin
data = YAML.load(io)
data = load_yaml(io)
rescue ArgumentError => e
case e.message
when %r{\Aundefined class/module Mechanize::}
Expand All @@ -31,7 +31,7 @@ def load(io, jar)
yaml = io.read
# a gross hack
yaml.gsub!(%r{^( [^ ].*:) !ruby/object:Mechanize::Cookie$}, "\\1")
data = YAML.load(yaml)
data = load_yaml(yaml)
rescue Errno::ESPIPE
@logger.warn "could not rewind the stream for conversion" if @logger
rescue ArgumentError
Expand Down Expand Up @@ -73,4 +73,14 @@ def load(io, jar)
def default_options
{}
end

if YAML.name == 'Psych' && Psych::VERSION >= '3.1'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"3.10" > "3.1", in case you wonder.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am so very late here (thanks for doing this update btw), but in the distant future "10.0" < "3.1" :)

def load_yaml(yaml)
YAML.safe_load(yaml, :permitted_classes => %w[Time HTTP::Cookie Mechanize::Cookie DomainName], :aliases => true)
end
else
def load_yaml(yaml)
YAML.load(yaml)
end
end
end