Skip to content

Commit

Permalink
Don't allow periods in dataset names
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel committed Nov 17, 2022
1 parent bdc9c19 commit 6099766
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pyxform/entities/entities_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def get_entity_declaration(workbook_dict: Dict, warnings: List) -> Dict:
f"Invalid dataset name: '{dataset}' starts with reserved prefix {constants.ENTITIES_RESERVED_PREFIX}."
)

if "." in dataset:
raise PyXFormError(
f"Invalid dataset name: '{dataset}'. Dataset names may not include periods."
)

if not is_valid_xml_tag(dataset):
if isinstance(dataset, bytes):
dataset = dataset.encode("utf-8")
Expand Down
17 changes: 17 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ def test_dataset_with_invalid_xml_name__errors(self):
],
)

def test_dataset_with_period_in_name__errors(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | label |
| | text | a | A |
| entities | | | |
| | dataset | label | |
| | s.w.eet | a | |
""",
errored=True,
error__contains=[
"Invalid dataset name: 's.w.eet'. Dataset names may not include periods."
],
)

def test_worksheet_name_close_to_entities__produces_warning(self):
self.assertPyxformXform(
name="data",
Expand Down

0 comments on commit 6099766

Please sign in to comment.