From 1282a211cfb35f5558e54318d488cb9455f2e7ff Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 17 Apr 2014 17:59:57 +0200 Subject: [PATCH] Add validation for search engine URLs and colors --- qutebrowser/config/conftypes.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/qutebrowser/config/conftypes.py b/qutebrowser/config/conftypes.py index 1ff1ff2ac..a1f31fd08 100644 --- a/qutebrowser/config/conftypes.py +++ b/qutebrowser/config/conftypes.py @@ -17,6 +17,8 @@ """Setting options used for qutebrowser.""" +from PyQt5.QtGui import QColor + class ValidationError(ValueError): @@ -281,13 +283,24 @@ class Command(BaseType): class Color(BaseType): - """Base class for a color value.""" + """Base class for a color value. + + Class attributes: + _GRADIENTS: Valid gradient function names. + """ typestr = 'color' + _GRADIENTS = ['qlineargradient', 'qradialgradient', 'qconicalgradient'] + def validate(self, value): - # FIXME validate colors - pass + if any([value.startswith(start) for start in Color._GRADIENTS]): + # We can't validate this further. + return + if QColor.isValidColor(value): + pass + else: + raise ValidationError(value, "must be a valid color") class Font(BaseType): @@ -314,7 +327,10 @@ class SearchEngineUrl(BaseType): """A search engine URL.""" def validate(self, value): - return "{}" in value + if "{}" in value: + pass + else: + raise ValidationError(value, 'must contain "{}"') class KeyBindingName(BaseType):