Commit 85a0f73d authored by Ray Bellis's avatar Ray Bellis

cache all dynamic (unknown) dict entries

(ensures that subsequent reference comparisons succeed)
parent c2f471fb
......@@ -220,14 +220,12 @@ function vsa(vendor_id, sub_id)
throw new TypeError('dictionary VSA attribute sub-id not an integer');
}
let dict = vsas.get(vendor_id);
if (dict && dict.has(sub_id)) {
return dict.get(sub_id);
} else {
let vnd = vendor(vendor_id);
let name = `${vnd.name}-Unknown-${sub_id}`;
return new DictionaryEntry(vnd, name, sub_id, "octets");
let v = vendor(vendor_id); // ensure the Vendor is known (or created)
let dict = vsas.get(v.id);
if (!dict.has(sub_id)) {
addAttributeSpec(v, `${v.name}-Unknown-${sub_id}`, sub_id, 'octets');
}
return dict.get(sub_id);
}
/**
......@@ -262,11 +260,10 @@ function get(id)
throw new RangeError(`dictionary lookup value out of range: ${id}`);
}
if (dict.has(id)) {
return dict.get(id);
} else {
return new DictionaryEntry(undefined, `Unknown-Attribute-${id}`, id, 'octets');
if (!dict.has(id)) {
addAttributeSpec(undefined, `Unknown-Attribute-${id}`, id, 'octets');
}
return dict.get(id);
}
/**
......
......@@ -37,6 +37,10 @@ describe('Dictionary', () => {
assert.equal(Dictionary.get(254).name, 'Unknown-Attribute-254');
});
it('should return the same entry if an unknown ID is requested twice', () => {
assert.equal(Dictionary.get(254), Dictionary.get(254));
});
it('should be able to parse attribute flags', () => {
assert.equal(Dictionary.get('User-Password').flags.encrypt, 1);
});
......@@ -65,6 +69,11 @@ describe('Dictionary', () => {
assert.equal(v.typeSize, 1);
assert.equal(v.lengthSize, 1);
});
it('should return the same vendor if an unknown value is requested twice', () => {
assert.equal(Dictionary.vendor(100), Dictionary.vendor(100));
});
});
describe('vsa', () => {
......@@ -94,5 +103,9 @@ describe('Dictionary', () => {
assert.equal(Dictionary.vsa(4846, 18).name, 'Lucent-Session-Type');
});
it('should return the same entry if an unknown value is requested twice', () => {
assert.equal(Dictionary.vsa(100, 10), Dictionary.vsa(100, 10));
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment