mirror of
https://github.com/python/cpython.git
synced 2025-08-14 22:01:08 +00:00
Issue #9130: Fix validation of relative imports in parser module.
This commit is contained in:
parent
a7ee59b3d3
commit
75b44b3437
3 changed files with 26 additions and 3 deletions
|
@ -1886,8 +1886,8 @@ count_from_dots(node *tree)
|
|||
return i-1;
|
||||
}
|
||||
|
||||
/* 'from' ('.'* dotted_name | '.') 'import' ('*' | '(' import_as_names ')' |
|
||||
* import_as_names
|
||||
/* import_from: ('from' ('.'* dotted_name | '.'+)
|
||||
* 'import' ('*' | '(' import_as_names ')' | import_as_names))
|
||||
*/
|
||||
static int
|
||||
validate_import_from(node *tree)
|
||||
|
@ -1897,7 +1897,8 @@ validate_import_from(node *tree)
|
|||
int havename = (TYPE(CHILD(tree, ndots + 1)) == dotted_name);
|
||||
int offset = ndots + havename;
|
||||
int res = validate_ntype(tree, import_from)
|
||||
&& (nch >= 4 + ndots)
|
||||
&& (offset >= 1)
|
||||
&& (nch >= 3 + offset)
|
||||
&& validate_name(CHILD(tree, 0), "from")
|
||||
&& (!havename || validate_dotted_name(CHILD(tree, ndots + 1)))
|
||||
&& validate_name(CHILD(tree, offset + 1), "import");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue