From 490109aeafb20e82d0ad95244c017d0d3d783126 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Tue, 10 Jun 2008 19:21:56 -0700 Subject: [PATCH] Module name sanity checking --- Cython/Compiler/Main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index 8d8832ba..aa47543c 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -23,6 +23,8 @@ from Errors import PyrexError, CompileError, error from Symtab import BuiltinScope, ModuleScope from Cython import Utils +module_name_pattern = re.compile(r"[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$") + # Note: PHASES and TransformSet should be removed soon; but that's for # another day and another commit. PHASES = [ @@ -74,6 +76,9 @@ class Context: module_name, relative_to, pos, need_pxd)) scope = None pxd_pathname = None + if not module_name_pattern.match(module_name): + raise CompileError((path, 0, 0), + "'%s' is not a valid module name" % module_name) if "." not in module_name and relative_to: if debug_find_module: print("...trying relative import") -- 2.26.2