◐ Shell
clean mode source ↗

Message 371179 - Python tracker

path 'g' in 'http:g' becomes '/g'.

    >>> urlsplit('http:g')
    SplitResult(scheme='http', netloc='', path='g', query='', fragment='')
    >>> urlunsplit(urlsplit('http:g'))
    'http:///g'
    >>> urlsplit('http:///g')
    SplitResult(scheme='http', netloc='', path='/g', query='', fragment='')

    >>> urljoin('http://a/b/c/d', 'http:g')
    'http://a/b/c/g'
    >>> urljoin('http://a/b/c/d', 'http:///g')
    'http://a/g'

The problematic part of the code is:

    def urlunsplit(components):
        [...]
        if netloc or (scheme and scheme in uses_netloc and url[:2] != '//'):
--->        if url and url[:1] != '/': url = '/' + url
            url = '//' + (netloc or '') + url

Note also that urllib has decided on the interpretation of 'http:g' (in test).

    def test_RFC3986(self):
        [...]
        #self.checkJoin(RFC3986_BASE, 'http:g','http:g') # strict parser
        self.checkJoin(RFC3986_BASE, 'http:g','http://a/b/c/g') #relaxed parser