Skip to content

Commit d16f49d

Browse files
committed
fix: isPrivateTag no longer silently returns false when given a tag whose last digit in the group is a hex digit.
Note: Direct calls to isPrivateTag can now throw a string as an exception if the tag is corrupt.
1 parent eb51626 commit d16f49d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/util/util.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ const isStringVr = (vr) => stringVrs[vr];
4141
* Tests to see if a given tag in the format xggggeeee is a private tag or not
4242
* @param tag
4343
* @returns {boolean}
44+
* @throws error if fourth character cannot be parsed
4445
*/
4546
const isPrivateTag = (tag) => {
46-
const lastGroupDigit = parseInt(tag[4], 10);
47+
const lastGroupDigit = parseInt(tag[4], 16);
48+
if (isNaN(lastGroupDigit)) {
49+
throw 'dicomParser.isPrivateTag: cannot parse last character of group';
50+
}
4751
const groupIsOdd = (lastGroupDigit % 2) === 1;
4852

49-
5053
return groupIsOdd;
5154
};
5255

test/util_test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('util', () => {
66
describe('#isPrivateTag', () => {
77

88
it('should return `true` for a private tag', () => {
9-
const isPrivateTag = util.isPrivateTag('x00190010');
9+
const isPrivateTag = util.isPrivateTag('x001d0010');
1010
expect(isPrivateTag).to.equal(true);
1111
})
1212

@@ -15,6 +15,15 @@ describe('util', () => {
1515
expect(isPrivateTag).to.equal(false);
1616
})
1717

18+
it('should throw an exception', () => {
19+
// Arrange
20+
const tag = 'x100z0010';
21+
const invoker = () => util.isPrivateTag(tag);
22+
23+
// Act / Assert
24+
expect(invoker).to.throw();
25+
});
26+
1827
});
1928

2029
describe('#parsePN', () => {

0 commit comments

Comments
 (0)