Revision 1d0dcc48
Added by Shlomi Zadok about 9 years ago
app/models/lookup_key.rb | ||
---|---|---|
def value_before_type_cast(val)
|
||
case key_type.to_sym
|
||
when :json, :array
|
||
val = JSON.dump val
|
||
begin
|
||
val = JSON.dump(val)
|
||
rescue JSON::GeneratorError => error
|
||
## http://projects.theforeman.org/issues/9553
|
||
## @TODO: remove when upgrading to json >= 1.8
|
||
logger.debug "Fallback to quirks mode from error: '#{error}'"
|
||
val = JSON.dump_in_quirks_mode(val)
|
||
end
|
||
when :yaml, :hash
|
||
val = YAML.dump val
|
||
val.sub!(/\A---\s*$\n/, '')
|
config/initializers/json.rb | ||
---|---|---|
require 'json/version'
|
||
module JSON
|
||
class << self
|
||
def dump_in_quirks_mode(obj, anIO = nil, limit = nil)
|
||
if anIO && limit.nil?
|
||
an_io_obj = anIO.to_io if anIO.respond_to?(:to_io)
|
||
unless anIO.respond_to?(:write)
|
||
limit = anIO
|
||
an_io_obj = nil
|
||
end
|
||
end
|
||
limit ||= 0
|
||
result = generate(obj, :allow_nan => true, :max_nesting => limit, :quirks_mode => true)
|
||
if an_io_obj
|
||
an_io_obj.write result
|
||
an_io_obj
|
||
else
|
||
result
|
||
end
|
||
rescue JSON::NestingError
|
||
raise ArgumentError, "exceed depth limit"
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
fixes #7764 - add quirks mode to JSON.dump
(cherry picked from commit 8dcb01a429e88a12edd605672e6f4340de7ca977)