Skip to content

Commit 063b68a

Browse files
ghamerlyaustrin
authored andcommitted
verifyproblem.py: check for invalid characters in data (directories and filenames)
Fixes #143. Also adds the ability to check names in other parts of verifyproblem.
1 parent 9d85d66 commit 063b68a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

problemtools/verifyproblem.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class ProblemAspect:
8383
warnings = 0
8484
bail_on_error = False
8585
_check_res = None
86+
basename_regex = re.compile('^[a-zA-Z0-9][a-zA-Z0-9_.-]*[a-zA-Z0-9]$')
8687

8788
@staticmethod
8889
def __append_additional_info(msg, additional_info):
@@ -123,6 +124,10 @@ def info(self, msg):
123124
def debug(self, msg):
124125
logging.debug(': %s', msg)
125126

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))
126131

127132
class TestCase(ProblemAspect):
128133
def __init__(self, problem, base, testcasegroup):
@@ -154,6 +159,8 @@ def check(self, args):
154159
if self._check_res is not None:
155160
return self._check_res
156161
self._check_res = True
162+
self.check_basename(self.infile)
163+
self.check_basename(self.ansfile)
157164
self.check_newlines(self.infile)
158165
self.check_newlines(self.ansfile)
159166
self._problem.input_format_validators.validate(self)
@@ -387,6 +394,8 @@ def check(self, args):
387394
return self._check_res
388395
self._check_res = True
389396

397+
self.check_basename(self._datadir)
398+
390399
if self.config['grading'] not in ['default', 'custom']:
391400
self.error("Invalid grading policy in testdata.yaml")
392401

@@ -1375,7 +1384,6 @@ def check(self, args):
13751384

13761385
return self._check_res
13771386

1378-
13791387
PROBLEM_PARTS = ['config', 'statement', 'validators', 'graders', 'data', 'submissions']
13801388

13811389
class Problem(ProblemAspect):

0 commit comments

Comments
 (0)