Merge pull request #2548 from brendandahl/isdict-fix
Fix isDict when type is missing in dictionary.
This commit is contained in:
commit
d111003cdb
@ -441,7 +441,14 @@ function isCmd(v, cmd) {
|
||||
}
|
||||
|
||||
function isDict(v, type) {
|
||||
return v instanceof Dict && (!type || v.get('Type').name == type);
|
||||
if (!(v instanceof Dict)) {
|
||||
return false;
|
||||
}
|
||||
if (!type) {
|
||||
return true;
|
||||
}
|
||||
var dictType = v.get('Type');
|
||||
return isName(dictType) && dictType.name == type;
|
||||
}
|
||||
|
||||
function isArray(v) {
|
||||
|
@ -63,5 +63,18 @@ describe('util', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isDict', function() {
|
||||
it('handles empty dictionaries with type check', function() {
|
||||
var dict = new Dict();
|
||||
expect(isDict(dict, 'Page')).toEqual(false);
|
||||
});
|
||||
|
||||
it('handles dictionaries with type check', function() {
|
||||
var dict = new Dict();
|
||||
dict.set('Type', new Name('Page'));
|
||||
expect(isDict(dict, 'Page')).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user