Repository navigation
fix(core): write an element with no value with zero length for every VR - #638
Merged
Merged
Conversation
DicomDict.write() threw "Cannot read properties of undefined (reading 'length')" for a string element with no Value, which is the DICOM JSON form of an empty element (NAT-U-RT-7). Tag.write now gives each VR writer an empty list for an absent, null, "" or all-undefined value, and turns another undefined entry into a null entry. A null sequence item is written as an empty item. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🎉 This PR is included in version 1.0.0-beta.14 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DicomDict.write()throwsTypeError: Cannot read properties of undefined (reading 'length')for a string element with noValue. A DICOM JSON element with noValueis the normal form of an empty element, for example an empty Type 2 attribute in DICOMweb metadata. NAT-U-RT-7 indocs/specs/naturalized-dataset.mdalready says that the writer writes such an element with zero length.The cause:
ValueRepresentation.writewrites nothing for anundefinedvalue. Then the basewriteByteschecks the value with=== nullonly, and readscheckValue.lengthofundefined.The same defect occurs in other forms:
Value: [undefined]throws for a string VR. A reader can give this form for a zero-length element (Tag value [undefined] causing unable to write a dicomDict #417).Value: [null]on an SQ throwsCannot convert undefined or null to objectinwriteDataSet.Before this fix,
Value: null,Value: ""andValue: []already wrote correctly in explicit VR.Changes
Tag.writechanges the value before the VR writer runs. Thus the rule applies to every VR:nullor""value becomes[].undefinedentries becomes[].undefinedentry beside another entry becomesnull. The existing null-entry rule then applies (an empty string value, an empty PN name, or0with a warning for a binary VR).SequenceOfItems.writeByteswrites anullitem as an empty item.docs/specs/naturalized-dataset.md: NAT-U-RT-7 lists the forms of an element with no value, and the new NAT-I-NULL-2 gives the implementation.Tests
test/core/absentValues.test.jswrites each of 34 VRs in 6 forms: noValuekey,undefined,null,"",[]and[undefined]. It writes in explicit VR little endian and in implicit VR little endian. The test reads the value length of each element from the written bytes, and expects 0 and no warning. Two more cases check anundefinedentry beside a value, and anullsequence item.test/issues/issue417-undefined-values.test.js: the skipped "KNOWN GAP" test now runs and passes. The test that expected the throwNot a number: undefinednow expects a write that succeeds.pnpm test: 1239 tests pass, and 11 tests are skipped. 3 tests oftest/data.test.jsfail (test_multiframe_1,test_oneslice_seg,test_deflated). The same 3 tests also fail on1.0-betawithout this change, because the local test data is missing.🤖 Generated with Claude Code