From a725a319b50057495b6335df2891334aa9b18069 Mon Sep 17 00:00:00 2001 From: Pavel Moravec Date: Tue, 1 Jan 2019 14:17:02 +0100 Subject: [plugins] Preserve data type of a plugin option to the default one Some plugin options rely on the default data type that can be automatically overwritten by Python (e.g. from str to int). The commit preserves the original data type to ensure implicit data type specified in option definition is always used. Resolves: #1526 Related: #1597 Signed-off-by: Pavel Moravec Signed-off-by: Bryn M. Reeves --- sos/plugins/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 2e30d86b..36efcb0e 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -547,9 +547,19 @@ class Plugin(object): return (self.opt_names, self.opt_parms) def set_option(self, optionname, value): - '''set the named option to value.''' + """Set the named option to value. Ensure the original type + of the option value is preserved. + """ for name, parms in zip(self.opt_names, self.opt_parms): if name == optionname: + # FIXME: ensure that the resulting type of the set option + # matches that of the default value. This prevents a string + # option from being coerced to int simply because it holds + # a numeric value (e.g. a password). + # See PR #1526 and Issue #1597 + defaulttype = type(parms['enabled']) + if defaulttype != type(value) and defaulttype != type(None): + value = (defaulttype)(value) parms['enabled'] = value return True else: -- cgit