From 0eab96d9857ebdfae72dad548a5d31752acdc6c0 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 31 Aug 2017 12:08:16 -0500 Subject: [PATCH 1/2] YAML parsing: catch and prevent lines that use tabs in indentation --- course/content.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/course/content.py b/course/content.py index 5c7e8bd3..407d1ada 100644 --- a/course/content.py +++ b/course/content.py @@ -579,6 +579,9 @@ def get_raw_yaml_from_repo(repo, full_name, commit_sha): return result +LINE_HAS_INDENTING_TABS_RE = re.compile("^\s*\t\s*", re.MULTILINE) + + def get_yaml_from_repo(repo, full_name, commit_sha, cached=True): # type: (Repo_ish, Text, bytes, bool) -> Any @@ -605,10 +608,16 @@ def get_yaml_from_repo(repo, full_name, commit_sha, cached=True): if result is not None: return result + yaml_bytestream = get_repo_blob( + repo, full_name, commit_sha, allow_tree=False).data + yaml_text = yaml_bytestream.decode("utf-8") + + if LINE_HAS_INDENTING_TABS_RE.search(yaml_text): + raise ValueError("File uses tabs in indentation. " + "This is not allowed.") + expanded = expand_yaml_macros( - repo, commit_sha, - get_repo_blob(repo, full_name, commit_sha, - allow_tree=False).data) + repo, commit_sha, yaml_bytestream) result = dict_to_struct(load_yaml(expanded)) -- GitLab From ede6ec12ddf4bbd05fce194c231df6a63f690fd0 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 31 Aug 2017 12:08:58 -0500 Subject: [PATCH 2/2] Fix indentation (=nesting) bug in static pages validation, which only caused the last static page to actually be validated --- course/validation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/course/validation.py b/course/validation.py index 06c4f644..27ed619c 100644 --- a/course/validation.py +++ b/course/validation.py @@ -1512,11 +1512,11 @@ def validate_course_content(repo, course_file, events_file, )) % entry_path) - location = "staticpages/%s" % entry_path - page_desc = get_yaml_from_repo_safely(repo, location, - commit_sha=validate_sha) + location = "staticpages/%s" % entry_path + page_desc = get_yaml_from_repo_safely(repo, location, + commit_sha=validate_sha) - validate_staticpage_desc(vctx, location, page_desc) + validate_staticpage_desc(vctx, location, page_desc) # }}} -- GitLab