Skip to content

Commit

Permalink
Fix E017/E018 handling (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeon committed Apr 20, 2021
1 parent 2c11ca2 commit 5a07d93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion ocfl/data/validation-errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@
"en": "OCFL Object version directory %s includes an illegal file (%s)"
}
},
"E017": {
"params": ["where"],
"description": {
"en": "OCFL Object %s inventory contentDirectory must be a string and must not contain a forward slash (/)"
}
},
"E018": {
"params": ["where"],
"description": {
"en": "Content directory must not contain a forward slash (/) or be . or .."
"en": "OCFL Object %s inventory contentDirectory must not be either . or .."
}
},
"E023": {
Expand Down
4 changes: 3 additions & 1 deletion ocfl/inventory_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def validate(self, inventory):
if 'contentDirectory' in inventory:
# Careful only to set self.content_directory if value is safe
cd = inventory['contentDirectory']
if not isinstance(cd, str) or '/' in cd or cd in ['.', '..']:
if not isinstance(cd, str) or '/' in cd:
self.error("E017")
elif cd in ('.', '..'):
self.error("E018")
else:
self.content_directory = cd
Expand Down
5 changes: 4 additions & 1 deletion tests/test_inventory_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def test_validate(self):
iv = InventoryValidator(log=log)
log.clear()
iv.validate({"id": "like:uri", "contentDirectory": "not/allowed"})
self.assertIn('E018', log.errors)
self.assertIn('E017', log.errors)
log.clear()
iv.validate({"id": "like:uri", "contentDirectory": ["s"]})
self.assertIn('E017', log.errors)
log.clear()
iv.validate({"id": "like:uri", "contentDirectory": ".."})
self.assertIn('E018', log.errors)
Expand Down

0 comments on commit 5a07d93

Please sign in to comment.