diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index e26a03454..a155726a8 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -30,7 +30,7 @@ import yaml from PyQt5.QtCore import QSettings import qutebrowser -from qutebrowser.config import configexc, config +from qutebrowser.config import configexc, config, configdata from qutebrowser.utils import standarddir, utils, qtutils @@ -153,6 +153,12 @@ class YamlConfig: "'global' object is not a dict") raise configexc.ConfigFileErrors('autoconfig.yml', [desc]) + # Delete unknown values + # (e.g. options which were removed from configdata.yml) + for name in list(global_obj): + if name not in configdata.DATA: + del global_obj[name] + self._values = global_obj self._dirty = False diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 6dff3c30a..36dc90c10 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -932,14 +932,9 @@ def test_early_init(init_patch, config_tmpdir, caplog, fake_args, expected_errors.append( "Errors occurred while reading config.py:\n" " While setting 'foo': No option 'foo'") - if invalid_yaml and (load_autoconfig or not config_py): + if invalid_yaml == '42' and (load_autoconfig or not config_py): error = "Errors occurred while reading autoconfig.yml:\n" - if invalid_yaml == '42': - error += " While loading data: Toplevel object is not a dict" - elif invalid_yaml == 'unknown': - error += " Error: No option 'colors.foobar'" - else: - assert False, invalid_yaml + error += " While loading data: Toplevel object is not a dict" expected_errors.append(error) actual_errors = [str(err) for err in config._init_errors] diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 219b92395..fdfda4033 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -57,6 +57,8 @@ def test_state_config(fake_save_manager, data_tmpdir, @pytest.mark.parametrize('old_config', [ None, 'global:\n colors.hints.fg: magenta', + # Unknown key + 'global:\n hello: world', ]) @pytest.mark.parametrize('insert', [True, False]) def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert): @@ -91,6 +93,7 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert): assert ' colors.hints.fg: magenta' in lines if insert: assert ' tabs.show: never' in lines + assert ' hello:' not in lines @pytest.mark.parametrize('old_config', [