From 7c45bf13fad2d60fbee8be409c6879af2ebc25d1 Mon Sep 17 00:00:00 2001 From: Dave B Date: Fri, 13 Nov 2015 11:50:22 -0500 Subject: [PATCH 1/3] Fix 500 error when attempting to update installed repository. --- lib/galaxy/util/__init__.py | 11 +++++++++++ .../webapps/tool_shed/framework/middleware/hg.py | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index 1d72feebf51..ff1cc69b01f 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -335,6 +335,17 @@ def shrink_string_by_size( value, size, join_by="..", left_larger=True, beginnin return value +def parse_query_string( query_string ): + if '=' not in query_string: + return {} + retval = {} + arguments = query_string.split( '&' ) + for argument in arguments: + key, value = argument.split( '=' ) + retval[ key ] = value + return retval + + def pretty_print_time_interval( time=False, precise=False ): """ Get a datetime object or a int() Epoch timestamp and return a diff --git a/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py b/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py index cdc1aa56cb2..008fb3c17cb 100644 --- a/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py +++ b/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py @@ -10,6 +10,7 @@ from paste.httpheaders import AUTH_TYPE from paste.httpheaders import REMOTE_USER from galaxy.util import asbool +from galaxy.util import parse_query_string from galaxy.util.hash_util import new_secure_hash from tool_shed.util import hg_util from tool_shed.util import commit_util @@ -49,11 +50,11 @@ class Hg( object ): # a clone or a pull. However, we do not want to increment the times_downloaded count if we're only setting repository # metadata. if cmd == 'getbundle' and not self.setting_repository_metadata: - common, _ = environ[ 'HTTP_X_HGARG_1' ].split( '&' ) + hg_args = parse_query_string( environ[ 'HTTP_X_HGARG_1' ] ) # The 'common' parameter indicates the full sha-1 hash of the changeset the client currently has checked out. If # this is 0000000000000000000000000000000000000000, then the client is performing a fresh checkout. If it has any # other value, the client is getting updates to an existing checkout. - if common == 'common=0000000000000000000000000000000000000000': + if 'common' in hg_args and hg_args[ 'common' ] == '0000000000000000000000000000000000000000': # Increment the value of the times_downloaded column in the repository table for the cloned repository. if 'PATH_INFO' in environ: # Instantiate a database connection From 321b64d8dcc1917eb107e46124cdb945c5005511 Mon Sep 17 00:00:00 2001 From: Dave B Date: Fri, 13 Nov 2015 12:44:35 -0500 Subject: [PATCH 2/3] Ensure that invalid parameters don't break things. --- lib/galaxy/util/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index ff1cc69b01f..8299579c758 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -341,6 +341,8 @@ def parse_query_string( query_string ): retval = {} arguments = query_string.split( '&' ) for argument in arguments: + if '=' not in argument: + continue key, value = argument.split( '=' ) retval[ key ] = value return retval From 87f35ea9752a37da76595db1fee481c391ee686b Mon Sep 17 00:00:00 2001 From: Dave B Date: Fri, 13 Nov 2015 14:37:44 -0500 Subject: [PATCH 3/3] Use preexisting library to parse query string. --- lib/galaxy/util/__init__.py | 13 ------------- .../webapps/tool_shed/framework/middleware/hg.py | 6 +++--- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index 8299579c758..1d72feebf51 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -335,19 +335,6 @@ def shrink_string_by_size( value, size, join_by="..", left_larger=True, beginnin return value -def parse_query_string( query_string ): - if '=' not in query_string: - return {} - retval = {} - arguments = query_string.split( '&' ) - for argument in arguments: - if '=' not in argument: - continue - key, value = argument.split( '=' ) - retval[ key ] = value - return retval - - def pretty_print_time_interval( time=False, precise=False ): """ Get a datetime object or a int() Epoch timestamp and return a diff --git a/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py b/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py index 008fb3c17cb..a7117efccbc 100644 --- a/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py +++ b/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py @@ -5,12 +5,12 @@ import os import sqlalchemy import sys import tempfile +import urlparse from paste.auth.basic import AuthBasicAuthenticator from paste.httpheaders import AUTH_TYPE from paste.httpheaders import REMOTE_USER from galaxy.util import asbool -from galaxy.util import parse_query_string from galaxy.util.hash_util import new_secure_hash from tool_shed.util import hg_util from tool_shed.util import commit_util @@ -50,11 +50,11 @@ class Hg( object ): # a clone or a pull. However, we do not want to increment the times_downloaded count if we're only setting repository # metadata. if cmd == 'getbundle' and not self.setting_repository_metadata: - hg_args = parse_query_string( environ[ 'HTTP_X_HGARG_1' ] ) + hg_args = urlparse.parse_qs( environ[ 'HTTP_X_HGARG_1' ] ) # The 'common' parameter indicates the full sha-1 hash of the changeset the client currently has checked out. If # this is 0000000000000000000000000000000000000000, then the client is performing a fresh checkout. If it has any # other value, the client is getting updates to an existing checkout. - if 'common' in hg_args and hg_args[ 'common' ] == '0000000000000000000000000000000000000000': + if 'common' in hg_args and hg_args[ 'common' ][-1] == '0000000000000000000000000000000000000000': # Increment the value of the times_downloaded column in the repository table for the cloned repository. if 'PATH_INFO' in environ: # Instantiate a database connection