1
0

Fixed issue where default values would leak when calling pretty

A clone of the given options are maintained instead.
This commit is contained in:
Jon Michael Aanes 2017-07-20 13:43:30 +02:00
parent ff2c70082a
commit 8f8e5b9c7f

View File

@ -611,10 +611,16 @@ local KNOWN_OPTIONS = {
recursion = { type = 'string', default = 'ignore', accepted = {['ignore'] = true, ['marked'] = true} }, recursion = { type = 'string', default = 'ignore', accepted = {['ignore'] = true, ['marked'] = true} },
} }
local function ensure_that_all_options_are_known (options) local function ensure_that_all_options_are_known (input_options)
assert(type(options) == 'table') -- Goes through all the given options, throws error if one is unknown, gives
-- warning if debug or experimental. Creates a clone of the given table, to
-- avoid defaults leaking.
-- Error check that options were table
assert(type(input_options) == 'table')
-- Error check options -- Error check options
for option_name, option_value in pairs(options) do for option_name, option_value in pairs(input_options) do
if not KNOWN_OPTIONS[option_name] then if not KNOWN_OPTIONS[option_name] then
error(('[pretty]: Unknown option: %s. Was given value %s (%s)'):format(option_name, option_value, type(option_value)), 2) error(('[pretty]: Unknown option: %s. Was given value %s (%s)'):format(option_name, option_value, type(option_value)), 2)
elseif type(option_value) ~= KNOWN_OPTIONS[option_name].type then elseif type(option_value) ~= KNOWN_OPTIONS[option_name].type then
@ -626,14 +632,19 @@ local function ensure_that_all_options_are_known (options)
print(('[pretty]: Using %s option "%s".\n Please note that this option may change at any time. It is not stable,\n not tested, and may indeed break or be removed without warning.'):format(KNOWN_OPTIONS[option_name].debug, option_name)) print(('[pretty]: Using %s option "%s".\n Please note that this option may change at any time. It is not stable,\n not tested, and may indeed break or be removed without warning.'):format(KNOWN_OPTIONS[option_name].debug, option_name))
end end
end end
-- Create output options
local output_options = {}
-- Assign default values -- Assign default values
for option_name, option_info in pairs(KNOWN_OPTIONS) do for option_name, option_info in pairs(KNOWN_OPTIONS) do
if options[option_name] == nil then if input_options[option_name] ~= nil then
options[option_name] = option_info.default output_options[option_name] = input_options[option_name]
else
output_options[option_name] = option_info.default
end end
end end
-- Returns options -- Returns input_options
return options return output_options
end end
local function pretty_format (value, options) local function pretty_format (value, options)