Projet

Général

Profil

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

Frédéric Péters, 03 mai 2016 18:38

Télécharger (4,35 ko)

Voir les différences:

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

 tests/test_variadic_url.py | 25 +++++++++++++++++++------
 wcs/qommon/misc.py         |  7 ++++---
 2 files changed, 23 insertions(+), 9 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',
......
61 67
            {'url': 'http://www.example.net/foobar'}) == 'http://www.example.net/foobar'
62 68

  
63 69
def test_url_server():
64
    assert get_variadic_url('[url]/foobar',
65
            {'url': 'http://www.example.net'}) == 'http://www.example.net/foobar'
66
    assert get_variadic_url('[url]/foobar',
67
            {'url': 'http://www.example.net/'}) == 'http://www.example.net/foobar'
68
    assert get_variadic_url('[url]foobar',
69
            {'url': 'http://www.example.net/'}) == 'http://www.example.net/foobar'
70
    for url in ('http://www.example.net', 'http://www.example.net/'):
71
        assert get_variadic_url('[url]/foobar',
72
                {'url': url}) == 'http://www.example.net/foobar'
73
        assert get_variadic_url('[url]/foobar',
74
                {'url': url}) == 'http://www.example.net/foobar'
75
        assert get_variadic_url('[url]/foobar/',
76
                {'url': url}) == 'http://www.example.net/foobar/'
77
    assert get_variadic_url('[url]foo/bar/',
78
            {'url': 'http://www.example.net/'}) == 'http://www.example.net/foo/bar/'
79
    assert get_variadic_url('[url]foobar/',
80
            {'url': 'http://www.example.net/'}) == 'http://www.example.net/foobar/'
81
    assert get_variadic_url('[url]foo/bar',
82
            {'url': 'http://www.example.net/'}) == 'http://www.example.net/foo/bar'
70 83

  
71 84
def test_url_server_qs():
72 85
    assert get_variadic_url('[url]?foo=bar',
wcs/qommon/misc.py
332 332
            # (ex: http[https]://www.example.net) or because the value starts
333 333
            # with a variable name (ex: [url]); in that situation we do not
334 334
            # quote at all.
335
            if path.count('/') >= 2:
335
            if path.count('//') == 1:
336 336
                # there were no / in the original path (the two / comes from
337
                # the scheme/netloc separation, this means there is no path
337
                # the scheme/netloc separation, this means there is no path)
338 338
                before_path = ezt_substitute(path, variables)
339 339
                p2 = urlparse.urlsplit(before_path)
340 340
                scheme, netloc, path = p2.scheme, p2.netloc, p2.path
341 341
            else:
342 342
                # there is a path, we need to get back to the original URL and
343 343
                # split it on the last /, to isolate the path part.
344
                lastslash = '/' if path.endswith('/') else ''
344 345
                if '/' in path:
345 346
                    before_path, path = path.rsplit('/', 1)
346 347
                else:
......
350 351
                scheme, netloc = p2.scheme, p2.netloc
351 352
                if p2.path:
352 353
                    if not path:
353
                        path, query2 = p2.path, p2.query
354
                        path, query2 = p2.path + lastslash, p2.query
354 355
                    else:
355 356
                        path, query2 = p2.path + '/' + path, p2.query
356 357
                    if query and query2:
357
-