Skip to content

Commit

Permalink
Move included content verification to separate function, fix root con…
Browse files Browse the repository at this point in the history
…tent.json file path verification
  • Loading branch information
shortcutme committed Jul 13, 2017
1 parent dd11f87 commit 13157ee
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Content/ContentManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,24 @@ def verifyContent(self, inner_path, content):
self.site.worker_manager.failTask(task)
raise VerifyError("Site too large %sB > %sB, aborting task..." % (site_size, site_size_limit))

# Verify valid filenames
for file_relative_path in content.get("files", {}).keys() + content.get("files_optional", {}).keys():
if not self.isValidRelativePath(file_relative_path):
raise VerifyError("Invalid relative path: %s" % file_relative_path)

if inner_path == "content.json":
self.site.settings["size"] = site_size
self.site.settings["size_optional"] = site_size_optional
return True # Root content.json is passed
else:
if self.verifyContentInclude(inner_path, content, content_size, content_size_optional):
self.site.settings["size"] = site_size
self.site.settings["size_optional"] = site_size_optional
return True
else:
return False

def verifyContentInclude(self, inner_path, content, content_size, content_size_optional):
# Load include details
rules = self.getRules(inner_path, content)
if not rules:
Expand All @@ -753,10 +766,6 @@ def verifyContent(self, inner_path, content):
content_size_optional, rules["max_size_optional"])
)

for file_relative_path in content.get("files", {}).keys() + content.get("files_optional", {}).keys():
if not self.isValidRelativePath(file_relative_path):
raise VerifyError("Invalid relative path: %s" % file_relative_path)

# Filename limit
if rules.get("files_allowed"):
for file_inner_path in content["files"].keys():
Expand All @@ -772,9 +781,6 @@ def verifyContent(self, inner_path, content):
if rules.get("includes_allowed") is False and content.get("includes"):
raise VerifyError("Includes not allowed")

self.site.settings["size"] = site_size
self.site.settings["size_optional"] = site_size_optional

return True # All good

# Verify file validity
Expand Down

0 comments on commit 13157ee

Please sign in to comment.