Projet

Général

Profil

0001-misc-support-variadic-URL-with-trailing-10813.patch

Thomas Noël, 03 mai 2016 17:02

Télécharger (3,65 ko)

Voir les différences:

Subject: [PATCH] misc: support variadic URL with trailing / (#10813)

 tests/test_variadic_url.py | 12 ++++++++++++
 wcs/qommon/misc.py         |  7 ++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
tests/test_variadic_url.py
9 9
                      {'https': 's'}) == 'https://www.example.net/foobar'
10 10
    assert get_variadic_url('http[https]://www.example.net/foobar',
11 11
                      {'https': ''}) == 'http://www.example.net/foobar'
12
    assert get_variadic_url('http[https]://www.example.net/foobar/',
13
                      {'https': ''}) == 'http://www.example.net/foobar/'
14
    assert get_variadic_url('http[https]://www.example.net/foo/bar/',
15
                      {'https': ''}) == 'http://www.example.net/foo/bar/'
16
    assert get_variadic_url('http[https]://www.example.net/foo/bar',
17
                      {'https': ''}) == 'http://www.example.net/foo/bar'
12 18

  
13 19
def test_url_netloc():
14 20
    assert get_variadic_url('http://[hostname]/foobar',
......
67 73
            {'url': 'http://www.example.net/'}) == 'http://www.example.net/foobar'
68 74
    assert get_variadic_url('[url]foobar',
69 75
            {'url': 'http://www.example.net/'}) == 'http://www.example.net/foobar'
76
    assert get_variadic_url('[url]foo/bar/',
77
            {'url': 'http://www.example.net/'}) == 'http://www.example.net/foo/bar/'
78
    assert get_variadic_url('[url]foobar/',
79
            {'url': 'http://www.example.net/'}) == 'http://www.example.net/foobar/'
80
    assert get_variadic_url('[url]foo/bar',
81
            {'url': 'http://www.example.net/'}) == 'http://www.example.net/foo/bar'
70 82

  
71 83
def test_url_server_qs():
72 84
    assert get_variadic_url('[url]?foo=bar',
wcs/qommon/misc.py
316 316
            # (ex: http[https]://www.example.net) or because the value starts
317 317
            # with a variable name (ex: [url]); in that situation we do not
318 318
            # quote at all.
319
            if path.count('/') >= 2:
319
            if path.count('//') == 1:
320 320
                # there were no / in the original path (the two / comes from
321
                # the scheme/netloc separation, this means there is no path
321
                # the scheme/netloc separation, this means there is no path)
322 322
                before_path = ezt_substitute(path, variables)
323 323
                p2 = urlparse.urlsplit(before_path)
324 324
                scheme, netloc, path = p2.scheme, p2.netloc, p2.path
325 325
            else:
326 326
                # there is a path, we need to get back to the original URL and
327 327
                # split it on the last /, to isolate the path part.
328
                lastslash = '/' if path.endswith('/') else ''
328 329
                if '/' in path:
329 330
                    before_path, path = path.rsplit('/', 1)
330 331
                else:
......
334 335
                scheme, netloc = p2.scheme, p2.netloc
335 336
                if p2.path:
336 337
                    if not path:
337
                        path, query2 = p2.path, p2.query
338
                        path, query2 = p2.path + lastslash, p2.query
338 339
                    else:
339 340
                        path, query2 = p2.path + '/' + path, p2.query
340 341
                    if query and query2:
341
-