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: 13 additions & 1 deletion lib/mechanize/cookie_jar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def load(input, *options)
return super(input, opthash) if opthash[:format] != :yaml

begin
data = YAML.load(input) # rubocop:disable Security/YAMLLoad
data = load_yaml(input)
rescue ArgumentError
@logger.warn "unloadable YAML cookie data discarded" if @logger
return self
Expand All @@ -174,6 +174,18 @@ def load(input, *options)
return self
end
end

private

if YAML.name == "Psych" && Gem::Requirement.new(">= 3.1").satisfied_by?(Gem::Version.new(Psych::VERSION))
def load_yaml(yaml)
YAML.safe_load(yaml, aliases: true, permitted_classes: ["Mechanize::Cookie", "Time"])
end
else
def load_yaml(yaml)
YAML.load(yaml) # rubocop:disable Security/YAMLLoad
end
end
end

class ::HTTP::CookieJar
Expand Down