From a53da60d995f73536379ab73a5af8120744a3e7b Mon Sep 17 00:00:00 2001 From: "arnaud.bore" Date: Fri, 23 Jun 2023 12:54:18 -0400 Subject: [PATCH 1/2] fix participant --- dcm2bids/participant.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dcm2bids/participant.py b/dcm2bids/participant.py index 61f27f0b..c3d2e4cb 100644 --- a/dcm2bids/participant.py +++ b/dcm2bids/participant.py @@ -34,11 +34,14 @@ def name(self): def name(self, name): """ Prepend 'sub-' if necessary""" if name.startswith("sub-"): - self._name = name - + self._name = name else: self._name = "sub-" + name + if '_' in self._name or '-' in self._name.replace('sub-', ''): + raise NameError(f"Participant '{self._name}' contains forbidden character " + "(multiple - or _).") + @property def session(self): """ From 6b7957577b923938ee37f5513df398b1619a7d8a Mon Sep 17 00:00:00 2001 From: "arnaud.bore" Date: Wed, 28 Jun 2023 22:23:17 -0400 Subject: [PATCH 2/2] use only alphanumric characters --- dcm2bids/participant.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dcm2bids/participant.py b/dcm2bids/participant.py index c3d2e4cb..2956f721 100644 --- a/dcm2bids/participant.py +++ b/dcm2bids/participant.py @@ -34,13 +34,13 @@ def name(self): def name(self, name): """ Prepend 'sub-' if necessary""" if name.startswith("sub-"): - self._name = name + self._name = name else: self._name = "sub-" + name - if '_' in self._name or '-' in self._name.replace('sub-', ''): - raise NameError(f"Participant '{self._name}' contains forbidden character " - "(multiple - or _).") + if not self._name.replace('sub-', '').isalnum(): + raise NameError(f"Participant '{self._name.replace('sub-', '')}' " + "should contains only alphanumeric characters.") @property def session(self):