comparison mercurial/util.py @ 30036:3f4e1c033f40

url: fix crash by empty path with #fragments Before, "#foo" paths made hg crash. We've moved the #fragment parsing at 64fbd0de9773, but we shouldn't set path to None too early. This patch just removes the "if not path:" block since that's checked a few lines later.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 30 Sep 2016 21:38:47 +0900
parents 0f6d6fdd3c2a
children 42ead5b3aa7b
comparison
equal deleted inserted replaced
30035:02328b5d775d 30036:3f4e1c033f40
2375 2375
2376 >>> url('http://host/a?b#c') 2376 >>> url('http://host/a?b#c')
2377 <url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'> 2377 <url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'>
2378 >>> url('http://host/a?b#c', parsequery=False, parsefragment=False) 2378 >>> url('http://host/a?b#c', parsequery=False, parsefragment=False)
2379 <url scheme: 'http', host: 'host', path: 'a?b#c'> 2379 <url scheme: 'http', host: 'host', path: 'a?b#c'>
2380
2381 Empty path:
2382
2383 >>> url('')
2384 <url path: ''>
2385 >>> url('#a')
2386 <url path: '', fragment: 'a'>
2387 >>> url('http://host/')
2388 <url scheme: 'http', host: 'host', path: ''>
2389 >>> url('http://host/#a')
2390 <url scheme: 'http', host: 'host', path: '', fragment: 'a'>
2391
2392 Only scheme:
2393
2394 >>> url('http:')
2395 <url scheme: 'http'>
2380 """ 2396 """
2381 2397
2382 _safechars = "!~*'()+" 2398 _safechars = "!~*'()+"
2383 _safepchars = "/!~*'()+:\\" 2399 _safepchars = "/!~*'()+:\\"
2384 _matchscheme = remod.compile(r'^[a-zA-Z0-9+.\-]+:').match 2400 _matchscheme = remod.compile(r'^[a-zA-Z0-9+.\-]+:').match
2391 self._hostport = '' 2407 self._hostport = ''
2392 self._origpath = path 2408 self._origpath = path
2393 2409
2394 if parsefragment and '#' in path: 2410 if parsefragment and '#' in path:
2395 path, self.fragment = path.split('#', 1) 2411 path, self.fragment = path.split('#', 1)
2396 if not path:
2397 path = None
2398 2412
2399 # special case for Windows drive letters and UNC paths 2413 # special case for Windows drive letters and UNC paths
2400 if hasdriveletter(path) or path.startswith(r'\\'): 2414 if hasdriveletter(path) or path.startswith(r'\\'):
2401 self.path = path 2415 self.path = path
2402 return 2416 return