From 2fb3bd8d06eedc4dae0062a5ac6f50e1e03feeac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9l=C3=A8ne=20Martin?= Date: Thu, 17 Nov 2022 11:07:40 -0800 Subject: [PATCH] Don't allow periods in dataset names --- pyxform/entities/entities_parsing.py | 7 ++++++- tests/test_entities.py | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pyxform/entities/entities_parsing.py b/pyxform/entities/entities_parsing.py index 7f6b9460..e985ee44 100644 --- a/pyxform/entities/entities_parsing.py +++ b/pyxform/entities/entities_parsing.py @@ -28,12 +28,17 @@ 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") raise PyXFormError( - f"Invalid dataset name: '{dataset}'. Dataset names {constants.XML_IDENTIFIER_ERROR_MESSAGE}" + f"Invalid dataset name: '{dataset}'. Dataset names must begin with a letter, colon, or underscore. Other characters can include numbers or dashes." ) if not ("label" in entity): diff --git a/tests/test_entities.py b/tests/test_entities.py index 2b99db69..4b62365a 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -81,7 +81,24 @@ def test_dataset_with_invalid_xml_name__errors(self): """, errored=True, error__contains=[ - "Invalid dataset name: '$sweet'. Dataset names must begin with a letter, colon, or underscore. Other characters can include numbers, dashes, and periods." + "Invalid dataset name: '$sweet'. Dataset names must begin with a letter, colon, or underscore. Other characters can include numbers or dashes." + ], + ) + + 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." ], )