summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2019-12-19 18:52:58 +0100
committerFlorian Bruhin <me@the-compiler.org>2019-12-20 16:53:17 +0100
commit5985b474c828b46d5297644b748f434d91211690 (patch)
tree4138b7aebbfff27f2a9e0c548110774992b87d69
parent069b5cb629e6f7e8be4e4b3b22d98a044b8f0ca4 (diff)
downloadqutebrowser-5985b474c828b46d5297644b748f434d91211690.tar.gz
qutebrowser-5985b474c828b46d5297644b748f434d91211690.zip
Make it possible to hide ScopedValues from dump_userconfig()
Fixes #4076
-rw-r--r--doc/changelog.asciidoc2
-rw-r--r--qutebrowser/config/config.py24
-rw-r--r--qutebrowser/config/configutils.py36
-rw-r--r--qutebrowser/config/websettings.py3
-rw-r--r--tests/unit/config/test_configutils.py25
-rw-r--r--tests/unit/config/test_websettings.py12
6 files changed, 83 insertions, 19 deletions
diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc
index a23587938..ba2eb8182 100644
--- a/doc/changelog.asciidoc
+++ b/doc/changelog.asciidoc
@@ -78,6 +78,8 @@ Fixed
QtWebKit.
- Workaround for a Qt bug where a page never finishes loading with a
non-overridable TLS error (e.g. due to HSTS).
+- The `qute://configdiff` page now doesn't show built-in settings (e.g.
+ javascript being enabled for `qute://` and `chrome://` pages) anymore.
- Various improvements for URL/searchengine detection:
- Strings with a dot but with characters not allowed in a URL (e.g. an
underscore) are now not treated as URL anymore.
diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py
index fdb55ce4b..7e10a91f3 100644
--- a/qutebrowser/config/config.py
+++ b/qutebrowser/config/config.py
@@ -307,7 +307,8 @@ class Config(QObject):
def _set_value(self,
opt: 'configdata.Option',
value: Any,
- pattern: urlmatch.UrlPattern = None) -> None:
+ pattern: urlmatch.UrlPattern = None,
+ hide_userconfig: bool = False) -> None:
"""Set the given option to the given value."""
if not isinstance(objects.backend, objects.NoBackend):
if objects.backend not in opt.backends:
@@ -316,7 +317,8 @@ class Config(QObject):
opt.typ.to_py(value) # for validation
- self._values[opt.name].add(opt.typ.from_obj(value), pattern)
+ self._values[opt.name].add(opt.typ.from_obj(value),
+ pattern, hide_userconfig=hide_userconfig)
self.changed.emit(opt.name)
log.config.debug("Config option changed: {} = {}".format(
@@ -442,14 +444,19 @@ class Config(QObject):
def set_obj(self, name: str,
value: Any, *,
pattern: urlmatch.UrlPattern = None,
- save_yaml: bool = False) -> None:
+ save_yaml: bool = False,
+ hide_userconfig: bool = False) -> None:
"""Set the given setting from a YAML/config.py object.
If save_yaml=True is given, store the new value to YAML.
+
+ If hide_userconfig=True is given, hide the value from
+ dump_userconfig().
"""
opt = self.get_opt(name)
self._check_yaml(opt, save_yaml)
- self._set_value(opt, value, pattern=pattern)
+ self._set_value(opt, value, pattern=pattern,
+ hide_userconfig=hide_userconfig)
if save_yaml:
self._yaml.set_obj(name, value, pattern=pattern)
@@ -519,15 +526,14 @@ class Config(QObject):
Return:
The changed config part as string.
"""
- blocks = []
+ lines = [] # type: typing.List[str]
for values in sorted(self, key=lambda v: v.opt.name):
- if values:
- blocks.append(str(values))
+ lines += values.dump()
- if not blocks:
+ if not lines:
return '<Default configuration>'
- return '\n'.join(blocks)
+ return '\n'.join(lines)
class ConfigContainer:
diff --git a/qutebrowser/config/configutils.py b/qutebrowser/config/configutils.py
index 8997aef36..758b802fd 100644
--- a/qutebrowser/config/configutils.py
+++ b/qutebrowser/config/configutils.py
@@ -55,18 +55,22 @@ class ScopedValue:
Attributes:
value: The value itself.
pattern: The UrlPattern for the value, or None for global values.
+ hide_userconfig: Hide this customization from config.dump_userconfig().
"""
id_gen = itertools.count(0)
def __init__(self, value: typing.Any,
- pattern: typing.Optional[urlmatch.UrlPattern]) -> None:
+ pattern: typing.Optional[urlmatch.UrlPattern],
+ hide_userconfig: bool = False) -> None:
self.value = value
self.pattern = pattern
+ self.hide_userconfig = hide_userconfig
self.pattern_id = next(ScopedValue.id_gen)
def __repr__(self) -> str:
return utils.get_repr(self, value=self.value, pattern=self.pattern,
+ hide_userconfig=self.hide_userconfig,
pattern_id=self.pattern_id)
@@ -112,18 +116,31 @@ class Values:
def __str__(self) -> str:
"""Get the values as human-readable string."""
- if not self:
- return '{}: <unchanged>'.format(self.opt.name)
+ lines = self.dump(include_hidden=True)
+ if lines:
+ return '\n'.join(lines)
+ return '{}: <unchanged>'.format(self.opt.name)
+ def dump(self, include_hidden: bool = False) -> typing.Sequence[str]:
+ """Dump all customizations for this value.
+
+ Arguments:
+ include_hidden: Also show values with hide_userconfig=True.
+ """
lines = []
+
for scoped in self._vmap.values():
+ if scoped.hide_userconfig and not include_hidden:
+ continue
+
str_value = self.opt.typ.to_str(scoped.value)
if scoped.pattern is None:
lines.append('{} = {}'.format(self.opt.name, str_value))
else:
lines.append('{}: {} = {}'.format(
scoped.pattern, self.opt.name, str_value))
- return '\n'.join(lines)
+
+ return lines
def __iter__(self) -> typing.Iterator['ScopedValue']:
"""Yield ScopedValue elements.
@@ -144,11 +161,16 @@ class Values:
raise configexc.NoPatternError(self.opt.name)
def add(self, value: typing.Any,
- pattern: urlmatch.UrlPattern = None) -> None:
- """Add a value with the given pattern to the list of values."""
+ pattern: urlmatch.UrlPattern = None, *,
+ hide_userconfig: bool = False) -> None:
+ """Add a value with the given pattern to the list of values.
+
+ If hide_userconfig is given, the value is hidden from
+ config.dump_userconfig() and thus qute://configdiff.
+ """
self._check_pattern_support(pattern)
self.remove(pattern)
- scoped = ScopedValue(value, pattern)
+ scoped = ScopedValue(value, pattern, hide_userconfig=hide_userconfig)
self._vmap[pattern] = scoped
host = pattern.host if pattern else None
diff --git a/qutebrowser/config/websettings.py b/qutebrowser/config/websettings.py
index a4c271e6b..10c12ea0d 100644
--- a/qutebrowser/config/websettings.py
+++ b/qutebrowser/config/websettings.py
@@ -269,7 +269,8 @@ def init(args: argparse.Namespace) -> None:
# Make sure special URLs always get JS support
for pattern in ['file://*', 'chrome://*/*', 'qute://*/*']:
config.instance.set_obj('content.javascript.enabled', True,
- pattern=urlmatch.UrlPattern(pattern))
+ pattern=urlmatch.UrlPattern(pattern),
+ hide_userconfig=True)
@pyqtSlot()
diff --git a/tests/unit/config/test_configutils.py b/tests/unit/config/test_configutils.py
index e87e4ab93..90a7dbd88 100644
--- a/tests/unit/config/test_configutils.py
+++ b/tests/unit/config/test_configutils.py
@@ -62,6 +62,14 @@ def values(opt, pattern):
@pytest.fixture
+def mixed_values(opt, pattern):
+ scoped_values = [configutils.ScopedValue('global value', None),
+ configutils.ScopedValue('example value', pattern,
+ hide_userconfig=True)]
+ return configutils.Values(opt, scoped_values)
+
+
+@pytest.fixture
def empty_values(opt):
return configutils.Values(opt)
@@ -74,8 +82,21 @@ def test_str(values):
assert str(values) == '\n'.join(expected)
-def test_str_empty(empty_values):
- assert str(empty_values) == 'example.option: <unchanged>'
+def test_str_mixed(mixed_values):
+ expected = [
+ 'example.option = global value',
+ '*://www.example.com/: example.option = example value',
+ ]
+ assert str(mixed_values) == '\n'.join(expected)
+
+
+@pytest.mark.parametrize('include_hidden, expected', [
+ (True, ['example.option = global value',
+ '*://www.example.com/: example.option = example value']),
+ (False, ['example.option = global value']),
+])
+def test_dump(mixed_values, include_hidden, expected):
+ assert mixed_values.dump(include_hidden=include_hidden) == expected
def test_bool(values, empty_values):
diff --git a/tests/unit/config/test_websettings.py b/tests/unit/config/test_websettings.py
index 916c8d609..b00f24af9 100644
--- a/tests/unit/config/test_websettings.py
+++ b/tests/unit/config/test_websettings.py
@@ -90,3 +90,15 @@ def test_user_agent(monkeypatch, config_stub, qapp):
config_stub.val.content.headers.user_agent = 'test2 {qt_key}'
assert websettings.user_agent() == 'test2 QtWebEngine'
+
+
+def test_config_init(request, monkeypatch, config_stub):
+ if request.config.webengine:
+ from qutebrowser.browser.webengine import webenginesettings
+ monkeypatch.setattr(webenginesettings, 'init', lambda _args: None)
+ else:
+ from qutebrowser.browser.webkit import webkitsettings
+ monkeypatch.setattr(webkitsettings, 'init', lambda _args: None)
+
+ websettings.init(args=None)
+ assert config_stub.dump_userconfig() == '<Default configuration>'