Fix endless recursion while validating aliases

This commit is contained in:
Florian Bruhin 2017-07-01 22:08:50 +02:00
parent ac78039171
commit 065f82f485
2 changed files with 22 additions and 7 deletions

View File

@ -726,18 +726,32 @@ class Command(BaseType):
"""Base class for a command value with arguments.""" """Base class for a command value with arguments."""
# See to_py for details
unvalidated = False
def to_py(self, value): def to_py(self, value):
self._basic_py_validation(value, str) self._basic_py_validation(value, str)
if not value: if not value:
return None return None
# FIXME:conf is it okay to import runners.py here? # This requires some trickery, as runners.CommandParser uses
from qutebrowser.commands import runners, cmdexc # conf.val.aliases, which in turn map to a command again,
parser = runners.CommandParser() # leading to an endless recursion.
try: # To fix that, we turn off validating other commands (alias values)
list(parser.parse_all(value)) # while validating a command.
except cmdexc.Error as e: # FIXME:conf Can't test this because we don't have a real config in
raise configexc.ValidationError(value, str(e)) # TestCommand
if not Command.unvalidated: # pragma: no branch
Command.unvalidated = True
try:
from qutebrowser.commands import runners, cmdexc
parser = runners.CommandParser()
try:
list(parser.parse_all(value))
except cmdexc.Error as e:
raise configexc.ValidationError(value, str(e))
finally:
Command.unvalidated = False
return value return value

View File

@ -1035,6 +1035,7 @@ class TestCommand:
'cmd2': stubs.FakeCommand(desc="desc 2")}) 'cmd2': stubs.FakeCommand(desc="desc 2")})
monkeypatch.setattr(configtypes, 'cmdutils', cmd_utils) monkeypatch.setattr(configtypes, 'cmdutils', cmd_utils)
# FIXME:conf use some kind of config_stub here # FIXME:conf use some kind of config_stub here
# also remove the no branch pragma from configtypes.Command then
ns = types.SimpleNamespace() ns = types.SimpleNamespace()
ns.aliases = {'alias': 'cmd1'} ns.aliases = {'alias': 'cmd1'}
monkeypatch.setattr('qutebrowser.config.config.val', ns) monkeypatch.setattr('qutebrowser.config.config.val', ns)