Skip to content

Commit

Permalink
Merge pull request #210 from yagni/fix-private-tag-detection
Browse files Browse the repository at this point in the history
fix: isPrivateTag no longer silently returns false when given a tag w…
  • Loading branch information
yagni authored Sep 28, 2022
2 parents eb51626 + d16f49d commit 21378b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ const isStringVr = (vr) => stringVrs[vr];
* Tests to see if a given tag in the format xggggeeee is a private tag or not
* @param tag
* @returns {boolean}
* @throws error if fourth character cannot be parsed
*/
const isPrivateTag = (tag) => {
const lastGroupDigit = parseInt(tag[4], 10);
const lastGroupDigit = parseInt(tag[4], 16);
if (isNaN(lastGroupDigit)) {
throw 'dicomParser.isPrivateTag: cannot parse last character of group';
}
const groupIsOdd = (lastGroupDigit % 2) === 1;


return groupIsOdd;
};

Expand Down
11 changes: 10 additions & 1 deletion test/util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('util', () => {
describe('#isPrivateTag', () => {

it('should return `true` for a private tag', () => {
const isPrivateTag = util.isPrivateTag('x00190010');
const isPrivateTag = util.isPrivateTag('x001d0010');
expect(isPrivateTag).to.equal(true);
})

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

it('should throw an exception', () => {
// Arrange
const tag = 'x100z0010';
const invoker = () => util.isPrivateTag(tag);

// Act / Assert
expect(invoker).to.throw();
});

});

describe('#parsePN', () => {
Expand Down

0 comments on commit 21378b9

Please sign in to comment.