2017-10-10 04:58:22 -04:00
|
|
|
module Gem
|
|
|
|
|
|
|
|
###
|
|
|
|
# This module is used for safely loading YAML specs from a gem. The
|
|
|
|
# `safe_load` method defined on this module is specifically designed for
|
|
|
|
# loading Gem specifications. For loading other YAML safely, please see
|
|
|
|
# Psych.safe_load
|
|
|
|
|
|
|
|
module SafeYAML
|
2020-03-24 14:51:43 -04:00
|
|
|
PERMITTED_CLASSES = %w[
|
2017-10-10 04:58:22 -04:00
|
|
|
Symbol
|
|
|
|
Time
|
|
|
|
Date
|
|
|
|
Gem::Dependency
|
|
|
|
Gem::Platform
|
|
|
|
Gem::Requirement
|
|
|
|
Gem::Specification
|
|
|
|
Gem::Version
|
|
|
|
Gem::Version::Requirement
|
|
|
|
YAML::Syck::DefaultKey
|
|
|
|
Syck::DefaultKey
|
2020-03-24 14:51:43 -04:00
|
|
|
].freeze
|
2017-10-10 04:58:22 -04:00
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
PERMITTED_SYMBOLS = %w[
|
2017-10-10 04:58:22 -04:00
|
|
|
development
|
|
|
|
runtime
|
2020-03-24 14:51:43 -04:00
|
|
|
].freeze
|
2017-10-10 04:58:22 -04:00
|
|
|
|
|
|
|
if ::YAML.respond_to? :safe_load
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.safe_load(input)
|
2018-10-19 22:51:09 -04:00
|
|
|
if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1')
|
2018-11-10 19:20:27 -05:00
|
|
|
::YAML.safe_load(input, permitted_classes: PERMITTED_CLASSES, permitted_symbols: PERMITTED_SYMBOLS, aliases: true)
|
2018-10-19 22:51:09 -04:00
|
|
|
else
|
2018-11-10 19:20:27 -05:00
|
|
|
::YAML.safe_load(input, PERMITTED_CLASSES, PERMITTED_SYMBOLS, true)
|
2018-10-19 22:51:09 -04:00
|
|
|
end
|
2017-10-10 04:58:22 -04:00
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.load(input)
|
2018-10-19 22:51:09 -04:00
|
|
|
if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1')
|
2018-11-10 19:20:27 -05:00
|
|
|
::YAML.safe_load(input, permitted_classes: [::Symbol])
|
2018-10-19 22:51:09 -04:00
|
|
|
else
|
|
|
|
::YAML.safe_load(input, [::Symbol])
|
|
|
|
end
|
2017-10-10 04:58:22 -04:00
|
|
|
end
|
|
|
|
else
|
2017-11-02 00:25:37 -04:00
|
|
|
unless Gem::Deprecate.skip
|
|
|
|
warn "YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0)."
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.safe_load(input, *args)
|
2017-10-10 04:58:22 -04:00
|
|
|
::YAML.load input
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.load(input)
|
2017-10-10 04:58:22 -04:00
|
|
|
::YAML.load input
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|