diff --git a/docker/client.py b/docker/client.py index 1b5420e9cfcdc5b4f2e9939b34346fda390aa286..9f75ce73c77c4e1d26f2e1f50ce0a12f33729489 100644 --- a/docker/client.py +++ b/docker/client.py @@ -14,6 +14,7 @@ import json import struct +from functools import partial import requests import requests.exceptions @@ -157,7 +158,8 @@ class Client( 'instead'.format(arg, type(arg)) ) - args = map(six.moves.urllib.parse.quote_plus, args) + quote_f = partial(six.moves.urllib.parse.quote_plus, safe="/:") + args = map(quote_f, args) if kwargs.get('versioned_api', True): return '{0}/v{1}{2}'.format( diff --git a/tests/unit/api_test.py b/tests/unit/api_test.py index 696c073914e52ab68e4f85ee863da0dde82e89cb..712f57e0be2f1419ca43c0158dcf7f1372f46c94 100644 --- a/tests/unit/api_test.py +++ b/tests/unit/api_test.py @@ -159,9 +159,15 @@ class DockerApiTest(DockerClientTest): '{0}{1}'.format(url_prefix, 'hello/somename/world/someothername') ) - url = self.client._url('/hello/{0}/world', '/some?name') + url = self.client._url('/hello/{0}/world', 'some?name') self.assertEqual( - url, '{0}{1}'.format(url_prefix, 'hello/%2Fsome%3Fname/world') + url, '{0}{1}'.format(url_prefix, 'hello/some%3Fname/world') + ) + + url = self.client._url("/images/{0}/push", "localhost:5000/image") + self.assertEqual( + url, + '{0}{1}'.format(url_prefix, 'images/localhost:5000/image/push') ) def test_url_invalid_resource(self):