Skip to content

Commit a79f005

Browse files
committed
Fix isDict when type is missing in dictionary.
1 parent 2ccad4c commit a79f005

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/util.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,14 @@ function isCmd(v, cmd) {
441441
}
442442

443443
function isDict(v, type) {
444-
return v instanceof Dict && (!type || v.get('Type').name == type);
444+
if (!(v instanceof Dict)) {
445+
return false;
446+
}
447+
if (!type) {
448+
return true;
449+
}
450+
var dictType = v.get('Type');
451+
return isName(dictType) && dictType.name == type;
445452
}
446453

447454
function isArray(v) {

test/unit/util_spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,18 @@ describe('util', function() {
6363
});
6464
});
6565

66+
describe('isDict', function() {
67+
it('handles empty dictionaries with type check', function() {
68+
var dict = new Dict();
69+
expect(isDict(dict, 'Page')).toEqual(false);
70+
});
71+
72+
it('handles dictionaries with type check', function() {
73+
var dict = new Dict();
74+
dict.set('Type', new Name('Page'));
75+
expect(isDict(dict, 'Page')).toEqual(true);
76+
});
77+
});
78+
6679
});
6780

0 commit comments

Comments
 (0)