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.

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

88 class Lexer(object):
99 START_IDENTIFIER = set(string.ascii_letters + '_')
1010 VALID_IDENTIFIER = set(string.ascii_letters + string.digits + '_')
11- START_NUMBER = set(string.digits + '-')
1211 VALID_NUMBER = set(string.digits)
1312 WHITESPACE = set(" \t\n\r")
1413 SIMPLE_TOKENS = {
6261 yield self._match_or_else('|', 'or', 'pipe')
6362 elif self._current == '`':
6463 yield self._consume_literal()
65- elif self._current in self.START_NUMBER:
64+ elif self._current in self.VALID_NUMBER:
6665 start = self._position
67- buff = self._current
68- while self._next() in self.VALID_NUMBER:
69- buff += self._current
66+ buff = self._consume_number()
7067 yield {'type': 'number', 'value': int(buff),
7168 '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)
7280 elif self._current == '"':
7381 yield self._consume_quoted_identifier()
7482 elif self._current == '<':
8593 message="Unknown token %s" % self._current)
8694 yield {'type': 'eof', 'value': '',
8795 '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
88103
89104 def _initialize_for_expression(self, expression):
90105 if not expression:

The check that tells the two apart

failpass·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