From 54e2cea460915102358733aee3ac1f5944dc153a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 10 Nov 2015 21:27:42 +0100 Subject: [PATCH] Fix some corner cases with :set. --- CHANGELOG.asciidoc | 3 ++- qutebrowser/config/config.py | 10 ++++--- tests/integration/features/set.feature | 37 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index f94dfa4eb..ddfbc0116 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -84,7 +84,8 @@ Fixed - Fixed a crash when a website presents a very small favicon. - Fixed prompting for download directory when `storage -> prompt-download-directory` was unset. -- Fixed crash when using `:follow-hint outside of hint mode. +- Fixed crash when using `:follow-hint` outside of hint mode. +- Fixed crash when using `:set foo bar?` with invalid section/option. v0.4.1 ------ diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 55502c5da..7f1727924 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -699,12 +699,12 @@ class ConfigManager(QObject): tabbed_browser.openurl(QUrl('qute:settings'), newtab=False) return - if option.endswith('?'): + if option.endswith('?') and option != '?': option = option[:-1] print_ = True else: try: - if option.endswith('!') and value is None: + if option.endswith('!') and option != '!' and value is None: option = option[:-1] val = self.get(section_, option) layer = 'temp' if temp else 'conf' @@ -724,7 +724,11 @@ class ConfigManager(QObject): e.__class__.__name__, e)) if print_: - val = self.get(section_, option, transformed=False) + try: + val = self.get(section_, option, transformed=False) + except configexc.Error as e: + raise cmdexc.CommandError("set: {} - {}".format( + e.__class__.__name__, e)) message.info(win_id, "{} {} = {}".format( section_, option, val), immediately=True) diff --git a/tests/integration/features/set.feature b/tests/integration/features/set.feature index 1c9916e99..92c6c07bf 100644 --- a/tests/integration/features/set.feature +++ b/tests/integration/features/set.feature @@ -41,6 +41,11 @@ Feature: Setting settings. When I run :set -p colors statusbar.bg red Then the message "colors statusbar.bg = red" should be shown. + Scenario: Using ! and -p + When I run :set general auto-save-config false + And I run :set -p general auto-save-config! + Then the message "general auto-save-config = True" should be shown. + Scenario: Setting a temporary option # We don't actually check if the option is temporary as this isn't easy # to check. @@ -58,3 +63,35 @@ Feature: Setting settings. - url: about:blank - active: true url: qute:settings + + Scenario: Empty option with ? (issue 1109) + When I run :set general ? + Then the error "set: The following arguments are required: value" should be shown. + + Scenario: Invalid section and empty option with ? (issue 1109) + When I run :set blah ? + Then the error "set: The following arguments are required: value" should be shown. + + Scenario: Invalid option with ? (issue 1109) + When I run :set general foo? + Then the error "set: NoOptionError - No option 'foo' in section 'general'" should be shown. + + Scenario: Invalid section/option with ? (issue 1109) + When I run :set blah foo ? + Then the error "set: NoSectionError - Section 'blah' does not exist!" should be shown. + + Scenario: Empty option with ! + When I run :set general ! + Then the error "set: The following arguments are required: value" should be shown. + + Scenario: Invalid section and empty option with ! + When I run :set blah ! + Then the error "set: The following arguments are required: value" should be shown. + + Scenario: Invalid option with ! + When I run :set general foo! + Then the error "set: NoOptionError - No option 'foo' in section 'general'" should be shown. + + Scenario: Invalid section/option with ! + When I run :set blah foo ! + Then the error "set: NoSectionError - Section 'blah' does not exist!" should be shown.