diff --git a/lib/rails_admin/config/fields/types/serialized.rb b/lib/rails_admin/config/fields/types/serialized.rb index 3cf5599d1a..2fa52b2b17 100644 --- a/lib/rails_admin/config/fields/types/serialized.rb +++ b/lib/rails_admin/config/fields/types/serialized.rb @@ -14,7 +14,7 @@ class Serialized < RailsAdmin::Config::Fields::Types::Text def parse_input(params) return unless params[name].is_a?(::String) - params[name] = (params[name].blank? ? nil : (SafeYAML.load(params[name]) || nil)) + params[name] = (params[name].blank? ? nil : (RailsAdmin::SafeYAML.load(params[name]) || nil)) end end end diff --git a/lib/rails_admin/engine.rb b/lib/rails_admin/engine.rb index 69cd31a4fc..0fd84a6834 100644 --- a/lib/rails_admin/engine.rb +++ b/lib/rails_admin/engine.rb @@ -7,9 +7,28 @@ require 'rails' require 'rails_admin' require 'remotipart' -require 'safe_yaml/load' +require 'yaml' module RailsAdmin + # Backwards-compatible RailsAdmin::SafeYAML when SafeYAML isn't available + begin + require 'safe_yaml/load' + rescue LoadError + if YAML.respond_to?(:safe_load) + SafeYAML = Module.new do + def self.load(yaml) + YAML.safe_load(yaml) + end + end + else + warn "Safe-loading of YAML is not available. Please install 'safe_yaml' or install Psych 2.0+" + SafeYAML = Module.new do + def self.load(yaml) + YAML.load(yaml) + end + end + end + end class Engine < Rails::Engine isolate_namespace RailsAdmin diff --git a/rails_admin.gemspec b/rails_admin.gemspec index ab2ba79353..bc85cc0480 100644 --- a/rails_admin.gemspec +++ b/rails_admin.gemspec @@ -16,7 +16,6 @@ Gem::Specification.new do |spec| spec.add_dependency 'rack-pjax', '~> 0.7' spec.add_dependency 'rails', '~> 4.0' spec.add_dependency 'remotipart', '~> 1.0' - spec.add_dependency 'safe_yaml', '~> 1.0' spec.add_dependency 'sass-rails', ['>= 4.0', '< 6'] spec.add_development_dependency 'bundler', '~> 1.0' spec.authors = ['Erik Michaels-Ober', 'Bogdan Gaza', 'Petteri Kaapa', 'Benoit Benezech', 'Mitsuhiro Shibuya']