Skip to content

Commit 41d72b0

Browse files
committed
[tools/RDFWriter] Exclude all subclass whitespace
In homage to the unknown DAU all whitespaces are excluded from the custom RDF subclasses dict.
1 parent ce5f196 commit 41d72b0

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

odml/tools/rdf_converter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
import os
7+
import string
78
import uuid
89
import warnings
910

@@ -338,9 +339,10 @@ def _parse_custom_subclasses(self, custom_subclasses):
338339
otherwise.
339340
"""
340341

341-
# Do not allow whitespaces in values
342-
if " " in "".join(custom_subclasses.values()):
343-
msg = "Custom RDF Subclass names must not contain any whitespaces."
342+
# Do not allow any whitespace characters in values
343+
vals = "".join(custom_subclasses.values()).encode()
344+
if vals != vals.translate(None, string.whitespace.encode()):
345+
msg = "Custom RDF Subclass names must not contain any whitespace characters."
344346
raise ValueError(msg)
345347

346348
for k in custom_subclasses:

test/test_rdf_writer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,11 @@ def test_rdf_custom_subclasses(self):
338338
self.assertIn("odml:Cell", rdf_writer.get_rdf_str())
339339

340340
# Test value whitespace
341-
invalid_dict = {"type_1": "Class 1", "type_2": "Class 2"}
341+
inval_a = "This should"
342+
inval_b = "fail\nin"
343+
inval_c = "the\tmost"
344+
inval_d = "complete\rway"
345+
invalid_dict = {"type_1": inval_a, "type_2": inval_b, "type_3": inval_c, "type_4": inval_d}
342346
with self.assertRaises(ValueError):
343347
_ = RDFWriter([doc], custom_subclasses=invalid_dict)
344348

0 commit comments

Comments
 (0)