Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error when using colon for container name #1202

Merged
merged 9 commits into from
Nov 11, 2024
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### Enhancements
- Added support for expandable datasets of references for untyped and compound data types. @stephprince [#1188](https://github.com/hdmf-dev/hdmf/pull/1188)
- Improved html representation of data in `Containers` @h-mayorquin [#1100](https://github.com/hdmf-dev/hdmf/pull/1100)
- Improved html representation of data in `Container` objects. @h-mayorquin [#1100](https://github.com/hdmf-dev/hdmf/pull/1100)
- Added error when using colon for `Container` name. A colon cannot be used as a group name when writing to Zarr on Windows. @stephprince [#1202](https://github.com/hdmf-dev/hdmf/pull/1202)

### Bug fixes
- Fixed inaccurate error message when validating reference data types. @stephprince [#1199](https://github.com/hdmf-dev/hdmf/pull/1199)
Expand Down
4 changes: 2 additions & 2 deletions src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ def __new__(cls, *args, **kwargs):
@docval({'name': 'name', 'type': str, 'doc': 'the name of this container'})
def __init__(self, **kwargs):
name = getargs('name', kwargs)
if '/' in name:
raise ValueError("name '" + name + "' cannot contain '/'")
if ('/' in name or ':' in name) and not self._in_construct_mode:
raise ValueError(f"name '{name}' cannot contain a '/' or ':'")
self.__name = name
self.__field_values = dict()
self.__read_io = None
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ def test_set_parent_overwrite_proxy(self):
def test_slash_restriction(self):
self.assertRaises(ValueError, Container, 'bad/name')

# check no error raised in construct mode
child_obj = Container.__new__(Container, in_construct_mode=True)
child_obj.__init__('bad/name')

def test_colon_restriction(self):
self.assertRaises(ValueError, Container, 'bad:name')

# check no error raised in construct mode
child_obj = Container.__new__(Container, in_construct_mode=True)
child_obj.__init__('bad:name')

def test_set_modified_parent(self):
"""Test that set modified properly sets parent modified
"""
Expand Down
Loading