Skip to content

Commit 18a99d2

Browse files
author
amaury.forgeotdarc
committed
Issue2681: the literal 0o8 was wrongly accepted, and evaluated as float(0.0).
This happened only when 8 is the first digit. Credits go to Lukas Meuser. git-svn-id: http://svn.python.org/projects/python/trunk@62480 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent dee933a commit 18a99d2

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lib/test/test_compile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def test_literals_with_leading_zeroes(self):
183183
for arg in ["077787", "0xj", "0x.", "0e", "090000000000000",
184184
"080000000000000", "000000000000009", "000000000000008",
185185
"0b42", "0BADCAFE", "0o123456789", "0b1.1", "0o4.2",
186-
"0b101j2", "0o153j2", "0b100e1", "0o777e1"]:
186+
"0b101j2", "0o153j2", "0b100e1", "0o777e1", "0o8", "0o78"]:
187187
self.assertRaises(SyntaxError, eval, arg)
188188

189189
self.assertEqual(eval("0777"), 511)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 3?
1212
Core and builtins
1313
-----------------
1414

15+
- Issue #2681: The octal literal ``0o8`` was incorrecly acctepted. Now it
16+
properly raises a SyntaxError.
17+
1518
- Patch #2617: Reserved -J and -X arguments for Jython, IronPython and other
1619
implementations of Python.
1720

Parser/tokenizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
13511351
else if (c == 'o' || c == 'O') {
13521352
/* Octal */
13531353
c = tok_nextc(tok);
1354-
if (c < '0' || c > '8') {
1354+
if (c < '0' || c >= '8') {
13551355
tok->done = E_TOKEN;
13561356
tok_backup(tok, c);
13571357
return ERRORTOKEN;

0 commit comments

Comments
 (0)