Skip to content

Commit a2d9ece

Browse files
committed
Add missing bounds check
- prevents an exception during parsing - the root cause is a problem with the parser which creates incorrect output, the reason is still unknown - fixes pydicom#119
1 parent 14835d5 commit a2d9ece

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Dicom Validator Release Notes
22
The released versions correspond to PyPi releases.
33

4+
## Unreleased
5+
6+
### Fixes
7+
* Fixed a regression bug introduced in 0.6.1, leading to an exception during docbook parsing
8+
(see [#119](../../issues/119)).
9+
410
## [Version 0.6.1](https://pypi.python.org/pypi/dicom-validator/0.6.1) (2024-08-05)
511
Some condition parser fixes.
612

dicom_validator/spec_reader/condition_parser.py

+2
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ def _index_is_inside_string(value: str, index: int) -> bool:
350350

351351
def _get_const_value(self, value: str) -> Tuple[Optional[str], str]:
352352
value = value.strip()
353+
if not value:
354+
return None, ""
353355
if value[0] == value[-1] == '"':
354356
return value[1:-1], ""
355357
if re.match("^[A-Z0-9][A-Za-z0-9_ ]*$", value) is not None:

dicom_validator/tests/spec_reader/test_condition_parser.py

+9
Original file line numberDiff line numberDiff line change
@@ -955,3 +955,12 @@ def test_sop_class_matching(self, parser):
955955
]
956956
other_cond = result.other_condition
957957
assert other_cond is None
958+
959+
def test_empty_value_handled(self, parser):
960+
# regression test for an exception that happened due to a wrongly
961+
# read in condition, see #119
962+
result = parser.parse(
963+
"Required if segmented data is NOT used in an Image IOD "
964+
"or , or if the IOD is a Presentation State IOD."
965+
)
966+
assert result.type == ConditionType.UserDefined

0 commit comments

Comments
 (0)