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} },
}
local function ensure_that_all_options_are_known (options)
assert(type(options) == 'table')
local function ensure_that_all_options_are_known (input_options)
-- 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
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
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
@ -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))
end
end
-- Create output options
local output_options = {}
-- Assign default values
for option_name, option_info in pairs(KNOWN_OPTIONS) do
if options[option_name] == nil then
options[option_name] = option_info.default
if input_options[option_name] ~= nil then
output_options[option_name] = input_options[option_name]
else
output_options[option_name] = option_info.default
end
end
-- Returns options
return options
-- Returns input_options
return output_options
end
local function pretty_format (value, options)