Fix for #4977 by adding a cleanup function for CLI inputs

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2020-05-02 23:29:01 -04:00
parent 824018efa3
commit d9f2cdb171

View file

@ -166,8 +166,9 @@ module Inspec
end
end
input_name, input_value = pair.split("=")
input_value = clean_up_cli_input_value(input_value)
evt = Inspec::Input::Event.new(
value: input_value.chomp(","), # Trim trailing comma if any
value: input_value,
provider: :cli,
priority: 50
)
@ -175,6 +176,18 @@ module Inspec
end
end
# Remove trailing commas, resolve type.
def clean_up_cli_input_value(given_value)
value = given_value.chomp(",") # Trim trailing comma if any
if value =~ /^-?\d+$/
value = value.to_i
elsif value =~ /^-?\d+\.\d+$/
value = value.to_f
end
value
end
def bind_inputs_from_runner_api(profile_name, input_hash)
# TODO: move this into a core plugin