Repository navigation
fix: write a UV element with a null value instead of throwing - #551
Merged
Merged
Conversation
DataView.setBigUint64 refuses anything that is not a BigInt, so a UV element whose Value held a null entry or a plain Number threw "Cannot convert null to a BigInt" from DicomDict.write(). PS3.5 7.4 requires a Type 2 attribute to be written with zero length when the value is unknown, and the other numeric VRs already accept null entries and Number values through toInt/toFloat. Coerce UV values to BigInt on write: null and undefined entries become 0 like US/UL, and a null, undefined or empty scalar keeps the zero-length short-circuit. Fixes review finding 3 from the PR #512 review map. Co-Authored-By: Claude Fable 5 <[email protected]>
awatson1978
added a commit
that referenced
this pull request
Sep 30, 2026
…ne and event-stream findings Engine findings 1/3/4/24/25/27/28/32 landed as PRs #544-#551; the writers wave (#552-#557) fixed 5/6/7/11/22/23 in the ports and retired 14 by trimming the video factories from the core facade. Master verdicts are now verified against origin/master, not just triaged. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🎉 This PR is included in version 1.0.0-beta.1 🎉 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.
This fixes review finding 3 from the PR #512 review map: a UV element with a null value threw on write.
UV is the Unsigned 64-bit Very Long VR, and its bytes go out through
DataView.setBigUint64, which is the one DataView setter that refuses to coerce — hand it anything that is not already a BigInt and it throws aTypeError. So while a bareValue: nullwas fine (the basewrite()short-circuit turns it into a zero-length element), a null inside the value array — or a plain JavaScript Number, which is how most callers naturally spell an integer — blew up the wholeDicomDict.write()call:That matters for conformance: PS3.5 7.4 requires a Type 2 attribute to be present with zero length when its value is unknown, and a writer that throws on the null can never produce that element. It is also inconsistent with the neighboring numeric VRs — US and UL run their values through
toInt, so they already accept Numbers and numeric strings and quietly write a null entry as 0.The fix is small and lives in
Unsigned64BitVeryLong.writeBytesinsrc/ValueRepresentation.js: coerce each value to BigInt before the write. BigInts pass through untouched, Numbers and numeric strings go throughBigInt(v), and a null or undefined entry becomes 0 exactly the way US/UL treat it. A null, undefined or empty scalar is deliberately left alone so the existing zero-length short-circuit keeps producing the empty Type 2 element.The regression test is
test_uv_null_and_number_values_writeintest/data.test.js, sitting right next totest_null_number_vrs, which owns the null-numeric-write territory. It pins all seven value shapes —null,[null],undefined,[],[5],["5"],[BigInt(5)]— through a full write-then-read round trip, and it fails on the current branch head with the exactCannot convert null to a BigIntfrom the finding.One note for the checklist's "verify master" column: master (0.49.2,
81e7e11) has the identical uncoercedwriteBigUint64call, so[null]and Number values throw the same TypeError there; only the scalar-null zero-length path behaves. The defect is real on master too, minus the eager-coercion variant the review saw on the 1.0 development branch.🤖 Generated with Claude Code