From 08c20db2d04975278c40f5e165e4c99cc7209e66 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 14 Sep 2018 18:15:29 +0200 Subject: [PATCH] Use string comparison in parse_boolean instead of the (simple)json module. --- redash/settings/helpers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/redash/settings/helpers.py b/redash/settings/helpers.py index 880255843e..5e2f7990b1 100644 --- a/redash/settings/helpers.py +++ b/redash/settings/helpers.py @@ -2,7 +2,6 @@ import urlparse import urllib -import simplejson def parse_db_url(url): url_parts = urlparse.urlparse(url) @@ -38,8 +37,15 @@ def set_from_string(s): return set(array_from_string(s)) -def parse_boolean(str): - return simplejson.loads(str.lower()) +def parse_boolean(s): + """Takes a string and returns the equivalent as a boolean value.""" + s = s.strip().lower() + if s in ('yes', 'true', 'on', '1'): + return True + elif s in ('no', 'false', 'off', '0', 'none'): + return False + else: + raise ValueError('Invalid boolean value %r' % s) def int_or_none(value):