From b42323013d5fdb6dc47b487d2d863e0556fd85a8 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Fri, 15 Sep 2023 15:06:57 +0200 Subject: [PATCH] fix(config): make config file keys case sensitive Since the configparser library by default parses keys case insensitive (all lowercase), certain mappings, especially in the pulseaudio modules, could fail ("internal" pulseaudio device names are matched against entries in the configuration). fixes #992 --- bumblebee_status/core/config.py | 11 ++++++++--- tests/core/test_config.py | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bumblebee_status/core/config.py b/bumblebee_status/core/config.py index 1d4ebaa..0b564b3 100644 --- a/bumblebee_status/core/config.py +++ b/bumblebee_status/core/config.py @@ -240,11 +240,16 @@ class Config(util.store.Store): :param filename: path to the file to load """ - def load_config(self, filename): - if os.path.exists(filename): + def load_config(self, filename, content=None): + if os.path.exists(filename) or content != None: log.info("loading {}".format(filename)) tmp = RawConfigParser() - tmp.read(u"{}".format(filename)) + tmp.optionxform = str + + if content: + tmp.read_string(content) + else: + tmp.read(u"{}".format(filename)) if tmp.has_section("module-parameters"): for key, value in tmp.items("module-parameters"): diff --git a/tests/core/test_config.py b/tests/core/test_config.py index 762c674..02695cd 100644 --- a/tests/core/test_config.py +++ b/tests/core/test_config.py @@ -113,6 +113,12 @@ def test_missing_parameter(): assert cfg.get("test.key") == None assert cfg.get("test.key", "no-value-set") == "no-value-set" +def test_file_case_sensitivity(): + cfg = core.config.Config([]) + cfg.load_config("", content="[module-parameters]\ntest.key = VaLuE\ntest.KeY2 = value") + + assert cfg.get("test.key") == "VaLuE" + assert cfg.get("test.KeY2") == "value" # # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4