Skip to content

Commit

Permalink
verifyproblem.py: check for invalid characters in data (directories a…
Browse files Browse the repository at this point in the history
…nd filenames)

Fixes #143.

Also adds the ability to check names in other parts of verifyproblem.
  • Loading branch information
ghamerly authored and austrin committed Nov 13, 2019
1 parent 9d85d66 commit 063b68a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion problemtools/verifyproblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ProblemAspect:
warnings = 0
bail_on_error = False
_check_res = None
basename_regex = re.compile('^[a-zA-Z0-9][a-zA-Z0-9_.-]*[a-zA-Z0-9]$')

@staticmethod
def __append_additional_info(msg, additional_info):
Expand Down Expand Up @@ -123,6 +124,10 @@ def info(self, msg):
def debug(self, msg):
logging.debug(': %s', msg)

def check_basename(self, path):
basename = os.path.basename(path)
if not self.basename_regex.match(basename):
self.error("Invalid name '%s' (should match '%s')" % (basename, self.basename_regex.pattern))

class TestCase(ProblemAspect):
def __init__(self, problem, base, testcasegroup):
Expand Down Expand Up @@ -154,6 +159,8 @@ def check(self, args):
if self._check_res is not None:
return self._check_res
self._check_res = True
self.check_basename(self.infile)
self.check_basename(self.ansfile)
self.check_newlines(self.infile)
self.check_newlines(self.ansfile)
self._problem.input_format_validators.validate(self)
Expand Down Expand Up @@ -387,6 +394,8 @@ def check(self, args):
return self._check_res
self._check_res = True

self.check_basename(self._datadir)

if self.config['grading'] not in ['default', 'custom']:
self.error("Invalid grading policy in testdata.yaml")

Expand Down Expand Up @@ -1375,7 +1384,6 @@ def check(self, args):

return self._check_res


PROBLEM_PARTS = ['config', 'statement', 'validators', 'graders', 'data', 'submissions']

class Problem(ProblemAspect):
Expand Down

0 comments on commit 063b68a

Please sign in to comment.