From 6f08e85ad97fc99dde46848167fa3310c4275c32 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 3 Nov 2008 15:19:35 +0000 Subject: [PATCH] backport r67077 from the trunk: parser module now correctly validates relative imports --- Lib/test/test_parser.py | 2 ++ Misc/ACKS | 1 + Misc/NEWS | 2 ++ Modules/parsermodule.c | 4 ++-- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index 8aa1657e62..d76db6ce68 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -1,4 +1,5 @@ import parser +import os import unittest from test import test_support @@ -168,6 +169,7 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase): "from sys.path import (dirname, basename as my_basename)") self.check_suite( "from sys.path import (dirname, basename as my_basename,)") + self.check_suite("from .bogus import x") def test_basic_import_statement(self): self.check_suite("import sys") diff --git a/Misc/ACKS b/Misc/ACKS index c3a0942d29..dddc40db6c 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -60,6 +60,7 @@ Eric Beser Steven Bethard Stephen Bevan Ron Bickers +David Binger Dominic Binks Philippe Biondi Stuart Bishop diff --git a/Misc/NEWS b/Misc/NEWS index 6e8a25ad60..c8651c1820 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.5.3? Core and builtins ----------------- +- Issue #4048: The parser module now correctly validates relative imports. + - Issue #4176: Fixed a crash when pickling an object which ``__reduce__`` method does not return iterators for the 4th and 5th items. diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index e33197e396..e49e6000c4 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -1804,10 +1804,10 @@ static int count_from_dots(node *tree) { int i; - for (i = 0; i < NCH(tree); i++) + for (i = 1; i < NCH(tree); i++) if (TYPE(CHILD(tree, i)) != DOT) break; - return i; + return i-1; } /* 'from' ('.'* dotted_name | '.') 'import' ('*' | '(' import_as_names ')' | -- 2.40.0