@@ -83,6 +83,7 @@ class ProblemAspect:
83
83
warnings = 0
84
84
bail_on_error = False
85
85
_check_res = None
86
+ basename_regex = re .compile ('^[a-zA-Z0-9][a-zA-Z0-9_.-]*[a-zA-Z0-9]$' )
86
87
87
88
@staticmethod
88
89
def __append_additional_info (msg , additional_info ):
@@ -123,6 +124,10 @@ def info(self, msg):
123
124
def debug (self , msg ):
124
125
logging .debug (': %s' , msg )
125
126
127
+ def check_basename (self , path ):
128
+ basename = os .path .basename (path )
129
+ if not self .basename_regex .match (basename ):
130
+ self .error ("Invalid name '%s' (should match '%s')" % (basename , self .basename_regex .pattern ))
126
131
127
132
class TestCase (ProblemAspect ):
128
133
def __init__ (self , problem , base , testcasegroup ):
@@ -154,6 +159,8 @@ def check(self, args):
154
159
if self ._check_res is not None :
155
160
return self ._check_res
156
161
self ._check_res = True
162
+ self .check_basename (self .infile )
163
+ self .check_basename (self .ansfile )
157
164
self .check_newlines (self .infile )
158
165
self .check_newlines (self .ansfile )
159
166
self ._problem .input_format_validators .validate (self )
@@ -387,6 +394,8 @@ def check(self, args):
387
394
return self ._check_res
388
395
self ._check_res = True
389
396
397
+ self .check_basename (self ._datadir )
398
+
390
399
if self .config ['grading' ] not in ['default' , 'custom' ]:
391
400
self .error ("Invalid grading policy in testdata.yaml" )
392
401
@@ -1375,7 +1384,6 @@ def check(self, args):
1375
1384
1376
1385
return self ._check_res
1377
1386
1378
-
1379
1387
PROBLEM_PARTS = ['config' , 'statement' , 'validators' , 'graders' , 'data' , 'submissions' ]
1380
1388
1381
1389
class Problem (ProblemAspect ):
0 commit comments