Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/revsetlang.py Sat Apr 14 00:30:39 2018 +0900 +++ b/mercurial/revsetlang.py Tue Apr 17 21:59:58 2018 +0900 @@ -89,6 +89,9 @@ [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)] ''' + if not isinstance(program, bytes): + raise error.ProgrammingError('revset statement must be bytes, got %r' + % program) program = pycompat.bytestr(program) if syminitletters is None: syminitletters = _syminitletters @@ -581,6 +584,8 @@ elif c == 's': return _quote(arg) elif c == 'r': + if not isinstance(arg, bytes): + raise TypeError parse(arg) # make sure syntax errors are confined return '(%s)' % arg elif c == 'n':