Commit f5c6d8a2 authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

Handle spaces in Gerrit search options

Gerrit rejects requests with 400 Bad request if query string `q`
contains any spaces. Replace spaces with a plus sign solves the problem.

R=thakis@chromium.org

Bug: 1199692
Change-Id: Ic13dda378527594c6cf57b8cb2edf740517811ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2832653Reviewed-by: 's avatarGavin Mak <gavinmak@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
parent 942a1eef
...@@ -237,7 +237,7 @@ The script can abandon up to 100 CLs per invocation. ...@@ -237,7 +237,7 @@ The script can abandon up to 100 CLs per invocation.
Examples: Examples:
gerrit_client.py mass-abandon --host https://HOST -p 'project=repo2' gerrit_client.py mass-abandon --host https://HOST -p 'project=repo2'
gerrit_client.py mass-abandon --host https://HOST -p 'message=testing' gerrit_client.py mass-abandon --host https://HOST -p 'message=testing'
gerrit_client.py mass-abandon --host https://HOST -p 'is=wip' -p 'age:1y' gerrit_client.py mass-abandon --host https://HOST -p 'is=wip' -p 'age=1y'
''') ''')
def CMDmass_abandon(parser, args): def CMDmass_abandon(parser, args):
parser.add_option('-p', parser.add_option('-p',
......
...@@ -85,7 +85,7 @@ def _QueryString(params, first_param=None): ...@@ -85,7 +85,7 @@ def _QueryString(params, first_param=None):
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
""" """
q = [urllib.parse.quote(first_param)] if first_param else [] q = [urllib.parse.quote(first_param)] if first_param else []
q.extend(['%s:%s' % (key, val) for key, val in params]) q.extend(['%s:%s' % (key, val.replace(" ", "+")) for key, val in params])
return '+'.join(q) return '+'.join(q)
......
...@@ -425,11 +425,11 @@ class GerritUtilTest(unittest.TestCase): ...@@ -425,11 +425,11 @@ class GerritUtilTest(unittest.TestCase):
@mock.patch('gerrit_util.ReadHttpJsonResponse') @mock.patch('gerrit_util.ReadHttpJsonResponse')
def testQueryChanges(self, mockJsonResponse, mockCreateHttpConn): def testQueryChanges(self, mockJsonResponse, mockCreateHttpConn):
gerrit_util.QueryChanges( gerrit_util.QueryChanges(
'host', [('key', 'val'), ('foo', 'bar')], 'first param', limit=500, 'host', [('key', 'val'), ('foo', 'bar baz')], 'first param', limit=500,
o_params=['PARAM_A', 'PARAM_B'], start='start') o_params=['PARAM_A', 'PARAM_B'], start='start')
mockCreateHttpConn.assert_called_once_with( mockCreateHttpConn.assert_called_once_with(
'host', 'host',
('changes/?q=first%20param+key:val+foo:bar' ('changes/?q=first%20param+key:val+foo:bar+baz'
'&start=start' '&start=start'
'&n=500' '&n=500'
'&o=PARAM_A' '&o=PARAM_A'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment