Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revsetlang.py @ 37775:03d7f885d5f2
revsetlang: do not pass in non-bytes to parse()
Since parse() isn't a simple function, we shouldn't expect it would raise
TypeError or ValueError for invalid inputs. Before, TypeError was raised
at 'if pos != len(spec)', which was quite late to report an error.
This patch also makes tokenize() detect invalid object before converting
it to a py3-safe bytes.
Spotted while adding the 'revset(...)' hack to _parsewith().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 17 Apr 2018 21:59:58 +0900 |
parents | 29eb4cafeeb8 |
children | 52f19a840543 |
comparison
equal
deleted
inserted
replaced
37774:d6970628b95f | 37775:03d7f885d5f2 |
---|---|
87 Check that @ is a valid unquoted token character (issue3686): | 87 Check that @ is a valid unquoted token character (issue3686): |
88 >>> list(tokenize(b"@::")) | 88 >>> list(tokenize(b"@::")) |
89 [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)] | 89 [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)] |
90 | 90 |
91 ''' | 91 ''' |
92 if not isinstance(program, bytes): | |
93 raise error.ProgrammingError('revset statement must be bytes, got %r' | |
94 % program) | |
92 program = pycompat.bytestr(program) | 95 program = pycompat.bytestr(program) |
93 if syminitletters is None: | 96 if syminitletters is None: |
94 syminitletters = _syminitletters | 97 syminitletters = _syminitletters |
95 if symletters is None: | 98 if symletters is None: |
96 symletters = _symletters | 99 symletters = _symletters |
579 if c == 'd': | 582 if c == 'd': |
580 return '%d' % int(arg) | 583 return '%d' % int(arg) |
581 elif c == 's': | 584 elif c == 's': |
582 return _quote(arg) | 585 return _quote(arg) |
583 elif c == 'r': | 586 elif c == 'r': |
587 if not isinstance(arg, bytes): | |
588 raise TypeError | |
584 parse(arg) # make sure syntax errors are confined | 589 parse(arg) # make sure syntax errors are confined |
585 return '(%s)' % arg | 590 return '(%s)' % arg |
586 elif c == 'n': | 591 elif c == 'n': |
587 return _quote(node.hex(arg)) | 592 return _quote(node.hex(arg)) |
588 elif c == 'b': | 593 elif c == 'b': |