comparison hgext/convert/subversion.py @ 44968:75b59d221aa3 stable

py3: pass native string to urlreq.url2pathname() Of course, I’m not happy with the warning, but it’s better than crashing. Solving the problem properly is hard, and non-UTF-8 percent-encoded bytes in file URLs seem rare enough to block solving that all file URLs (even if not SVN-specific) will cause a crash.
author Manuel Jacob <me@manueljacob.de>
date Tue, 16 Jun 2020 14:00:20 +0200
parents 0c27d981131a
children d545b895234a
comparison
equal deleted inserted replaced
44967:de7bdb0e2a95 44968:75b59d221aa3
319 and path[:1] == b'/' 319 and path[:1] == b'/'
320 and path[1:2].isalpha() 320 and path[1:2].isalpha()
321 and path[2:6].lower() == b'%3a/' 321 and path[2:6].lower() == b'%3a/'
322 ): 322 ):
323 path = path[:2] + b':/' + path[6:] 323 path = path[:2] + b':/' + path[6:]
324 path = urlreq.url2pathname(path) 324 # pycompat.fsdecode() / pycompat.fsencode() are used so that bytes
325 # in the URL roundtrip correctly on Unix. urlreq.url2pathname() on
326 # py3 will decode percent-encoded bytes using the utf-8 encoding
327 # and the "replace" error handler. This means that it will not
328 # preserve non-UTF-8 bytes (https://bugs.python.org/issue40983).
329 # url.open() uses the reverse function (urlreq.pathname2url()) and
330 # has a similar problem
331 # (https://bz.mercurial-scm.org/show_bug.cgi?id=6357). It makes
332 # sense to solve both problems together and handle all file URLs
333 # consistently. For now, we warn.
334 unicodepath = urlreq.url2pathname(pycompat.fsdecode(path))
335 if pycompat.ispy3 and u'\N{REPLACEMENT CHARACTER}' in unicodepath:
336 ui.warn(
337 _(
338 b'on Python 3, we currently do not support non-UTF-8 '
339 b'percent-encoded bytes in file URLs for Subversion '
340 b'repositories\n'
341 )
342 )
343 path = pycompat.fsencode(unicodepath)
325 except ValueError: 344 except ValueError:
326 proto = b'file' 345 proto = b'file'
327 path = os.path.abspath(url) 346 path = os.path.abspath(url)
328 if proto == b'file': 347 if proto == b'file':
329 path = util.pconvert(path) 348 path = util.pconvert(path)