From 5094099f086ad88bed088fd98464bdda23b79712 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 4 Oct 2022 09:36:10 +0200 Subject: [PATCH] Disable configparser interpolation to allow unescaped '%' in values --- osc/OscConfigParser.py | 2 +- tests/test_config_parser.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/test_config_parser.py diff --git a/osc/OscConfigParser.py b/osc/OscConfigParser.py index eb718dc2..d7338358 100644 --- a/osc/OscConfigParser.py +++ b/osc/OscConfigParser.py @@ -211,7 +211,7 @@ class OscConfigParser(configparser.ConfigParser): """ def __init__(self, defaults=None): - super().__init__(defaults or {}) + super().__init__(defaults or {}, interpolation=None) self._sections = ConfigLineOrder() # XXX: unfortunately we have to override the _read() method from the ConfigParser() diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py new file mode 100644 index 00000000..102e89d3 --- /dev/null +++ b/tests/test_config_parser.py @@ -0,0 +1,26 @@ +import unittest + +from osc.OscConfigParser import OscConfigParser + + +class TestOscConfigParser(unittest.TestCase): + def setUp(self): + self.parser = OscConfigParser() + self.parser.read_string(""" +[general] +apiurl = http://localhost + +[http://localhost] +credentials_mgr_class= +user= +pass= +""") + + def test_disabled_interpolation(self): + # with interpolation on, this would raise + # ValueError: invalid interpolation syntax in '%' at position 0 + self.parser.set("http://localhost", "pass", "%") + + +if __name__ == "__main__": + unittest.main()