lostisland / faraday_middleware

Various Faraday middlewares for Faraday-based API wrappers
MIT License
556 stars 205 forks source link

Psych is default YAML Engine since Ruby 1.9.3 #241

Closed onk closed 4 years ago

onk commented 4 years ago

And Syck is removed since Ruby 2.0.0.


I think, SafeYAML is also deprecated in Ruby 2.3+. Use YAML.safe_load instead of SafeYAML.load.

class ParseYaml < ResponseMiddleware
  define_parser do |body, parser_options|
    YAML.safe_load(body, **(parser_options || {}))
  end
end

But there are two problems.

SafeYAML and YAML's option is not compatible.

This makes a breaking change.

YAML.safe_load option is not compatible in Ruby 2.3-2.7

Supporting all of this is a bit too complicated.

2.3, 2.4:

def self.safe_load yaml, whitelist_classes = [], whitelist_symbols = [], aliases = false, filename = nil

2.5: symbolize_names is added as kwargs

def self.safe_load yaml, whitelist_classes = [], whitelist_symbols = [], aliases = false, filename = nil, symbolize_names: false

2.6+: all arguments are now kwargs

def self.safe_load yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false
olleolleolle commented 4 years ago

I will merge the code change, and take the rest of the PR description into a new Issue which we can deal with separately.