From 845e43c1e537f66c8208165a82583b4ca814b1f0 Mon Sep 17 00:00:00 2001 From: guerler Date: Thu, 2 Mar 2017 23:45:11 -0500 Subject: [PATCH 1/2] Avoid autoconversion of boolean values when calling json loads Remove unused import Fix --- lib/galaxy/tools/parameters/basic.py | 3 --- lib/galaxy/util/json.py | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 0c9a2005eec..170d4cdc2b5 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -2,7 +2,6 @@ Basic tool parameters. """ import logging -import numbers import os import os.path import re @@ -131,8 +130,6 @@ class ToolParameter( object, Dictifiable ): def to_python( self, value, app ): """Convert a value created with to_json back to an object representation""" - if isinstance( value, numbers.Number ): - return unicodify( value ) return value def value_to_basic( self, value, app, use_security=False ): diff --git a/lib/galaxy/util/json.py b/lib/galaxy/util/json.py index 2f38b96ccc8..15996e5aa90 100644 --- a/lib/galaxy/util/json.py +++ b/lib/galaxy/util/json.py @@ -56,10 +56,13 @@ def swap_inf_nan( val ): def safe_loads( arg ): """ This is a wrapper around loads that returns the parsed value instead of - raising a value error. + raising a value error. It also avoids autoconversion of non-iterables + such as numeric and boolean. """ try: loaded = json.loads( arg ) + if loaded is not None and not isinstance( loaded, collections.Iterable ): + loaded = arg except ( TypeError, ValueError ): loaded = arg return loaded From cb27f921c7e82f09c675e1e472417ad47d65bfab Mon Sep 17 00:00:00 2001 From: guerler Date: Fri, 3 Mar 2017 02:35:54 -0500 Subject: [PATCH 2/2] Fix comment --- lib/galaxy/util/json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/util/json.py b/lib/galaxy/util/json.py index 15996e5aa90..6bd11fc73fd 100644 --- a/lib/galaxy/util/json.py +++ b/lib/galaxy/util/json.py @@ -57,7 +57,7 @@ def safe_loads( arg ): """ This is a wrapper around loads that returns the parsed value instead of raising a value error. It also avoids autoconversion of non-iterables - such as numeric and boolean. + i.e numeric and boolean values. """ try: loaded = json.loads( arg )