Remove unknown YAML data from config

I considered introducing another list of deleted options (or a "deleted: True"
in configdata.yml), similar to what we had with the old config.

However, let's take the easier route and just delete everything we don't know
from configdata.yml. If someone edits it by hand, it's their fault :P

See #2772, #2847
This commit is contained in:
Florian Bruhin 2017-09-21 16:29:40 +02:00
parent cb57525f69
commit 7cad8f41f2
3 changed files with 12 additions and 8 deletions

View File

@ -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

View File

@ -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]

View File

@ -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', [