Whole file
jmespath/jmespath.py
The author described this change as “Raise LexerError on invalid numbers”. It counts as a record because the check below fails on the code as it stood at 93024894f and passes on cefe47c52, with nothing else changed between the two runs.
Projectjmespath/jmespath.py
Fix saved2015-10-21
Sharing licenceMIT · LICENSE
Change size+20 −5
What the code was meant to do, written into the code itself as a save note
Raise LexerError on invalid numbers
The change
| 8 | 8 | class Lexer(object): | |
| 9 | 9 | START_IDENTIFIER = set(string.ascii_letters + '_') | |
| 10 | 10 | VALID_IDENTIFIER = set(string.ascii_letters + string.digits + '_') | |
| 11 | - | START_NUMBER = set(string.digits + '-') | |
| 12 | 11 | VALID_NUMBER = set(string.digits) | |
| 13 | 12 | WHITESPACE = set(" \t\n\r") | |
| 14 | 13 | SIMPLE_TOKENS = { | |
| ⋯ | |||
| 62 | 61 | yield self._match_or_else('|', 'or', 'pipe') | |
| 63 | 62 | elif self._current == '`': | |
| 64 | 63 | yield self._consume_literal() | |
| 65 | - | elif self._current in self.START_NUMBER: | |
| 64 | + | elif self._current in self.VALID_NUMBER: | |
| 66 | 65 | start = self._position | |
| 67 | - | buff = self._current | |
| 68 | - | while self._next() in self.VALID_NUMBER: | |
| 69 | - | buff += self._current | |
| 66 | + | buff = self._consume_number() | |
| 70 | 67 | yield {'type': 'number', 'value': int(buff), | |
| 71 | 68 | 'start': start, 'end': start + len(buff)} | |
| 69 | + | elif self._current == '-': | |
| 70 | + | # Negative number. | |
| 71 | + | start = self._position | |
| 72 | + | buff = self._consume_number() | |
| 73 | + | if len(buff) > 1: | |
| 74 | + | yield {'type': 'number', 'value': int(buff), | |
| 75 | + | 'start': start, 'end': start + len(buff)} | |
| 76 | + | else: | |
| 77 | + | raise LexerError(lexer_position=start, | |
| 78 | + | lexer_value=buff, | |
| 79 | + | message="Unknown token '%s'" % buff) | |
| 72 | 80 | elif self._current == '"': | |
| 73 | 81 | yield self._consume_quoted_identifier() | |
| 74 | 82 | elif self._current == '<': | |
| ⋯ | |||
| 85 | 93 | message="Unknown token %s" % self._current) | |
| 86 | 94 | yield {'type': 'eof', 'value': '', | |
| 87 | 95 | 'start': self._length, 'end': self._length} | |
| 96 | + | ||
| 97 | + | def _consume_number(self): | |
| 98 | + | start = self._position | |
| 99 | + | buff = self._current | |
| 100 | + | while self._next() in self.VALID_NUMBER: | |
| 101 | + | buff += self._current | |
| 102 | + | return buff | |
| 88 | 103 | ||
| 89 | 104 | def _initialize_for_expression(self, expression): | |
| 90 | 105 | if not expression: | |
The check that tells the two apart
fail→pass·tests/test_lexer.py::TestRegexLexer::test_unknown_character_with_identifier
Check file tests/test_lexer.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it93024894f4bb373d7760364bb307bee93f763c5f
Broken version dated2015-06-09
Modulejmespath.lexer
Units changedLexer
Fingerprintd1e7c3a7895eb1a6
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in jmespath/jmespath.py
- 2015-04-08Fix invalid-type error messages