diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index 8b16c701a..11e059302 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -201,17 +201,37 @@ class YamlConfig(QObject): def _build_values(self, settings): """Build up self._values from the values in the given dict.""" + errors = [] for name, yaml_values in settings.items(): + if not isinstance(yaml_values, dict): + errors.append(configexc.ConfigErrorDesc( + "While parsing {!r}".format(name), "value is not a dict")) + continue + values = configutils.Values(configdata.DATA[name]) if 'global' in yaml_values: values.add(yaml_values.pop('global')) - # FIXME:conf what if yaml_values is not a dict... for pattern, value in yaml_values.items(): - values.add(value, pattern) + if not isinstance(pattern, str): + errors.append(configexc.ConfigErrorDesc( + "While parsing {!r}".format(name), + "pattern is not of type string")) + continue + try: + urlpattern = urlmatch.UrlPattern(pattern) + except urlmatch.ParseError as e: + errors.append(configexc.ConfigErrorDesc( + "While parsing pattern {!r} for {!r}" + .format(pattern, name), e)) + continue + values.add(value, urlpattern) self._values[name] = values + if errors: + raise configexc.ConfigFileErrors('autoconfig.yml', errors) + def _handle_migrations(self, settings): """Migrate older configs to the newest format.""" # Simple renamed/deleted options diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 0e173e8ff..728dbb794 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -297,6 +297,12 @@ class TestYaml: ('settings: {}', 'While loading data', "Toplevel object does not contain 'config_version' key"), ('42', 'While loading data', "Toplevel object is not a dict"), + ('settings: {"content.images": 42}\nconfig_version: 2', + "While parsing 'content.images'", "value is not a dict"), + ('settings: {"content.images": {"https://": true}}\nconfig_version: 2', + "While parsing pattern 'https://' for 'content.images'", "Pattern without host"), + ('settings: {"content.images": {true: true}}\nconfig_version: 2', + "While parsing 'content.images'", "pattern is not of type string"), ]) def test_invalid(self, yaml, autoconfig, line, text, exception): autoconfig.write_raw(line)