Normalize keys when getting and removing metadata items

pull/3012/head
murgatroid99 9 years ago
parent cc248a27f2
commit 6b8a3a74f2
  1. 6
      src/node/src/metadata.js
  2. 8
      src/node/test/metadata_test.js

@ -102,21 +102,23 @@ Metadata.prototype.add = function(key, value) {
};
/**
* Remove the given key and any associated values.
* Remove the given key and any associated values. Normalizes the key.
* @param {String} key The key to remove
*/
Metadata.prototype.remove = function(key) {
key = normalizeKey(key);
if (Object.prototype.hasOwnProperty.call(this._internal_repr, key)) {
delete this._internal_repr[key];
}
};
/**
* Gets a list of all values associated with the key.
* Gets a list of all values associated with the key. Normalizes the key.
* @param {String} key The key to get
* @return {Array.<String|Buffer>} The values associated with that key
*/
Metadata.prototype.get = function(key) {
key = normalizeKey(key);
if (Object.prototype.hasOwnProperty.call(this._internal_repr, key)) {
return this._internal_repr[key];
} else {

@ -135,10 +135,10 @@ describe('Metadata', function() {
metadata.remove('key');
assert.deepEqual(metadata.get('key'), []);
});
it('does not normalize keys', function() {
it('Normalizes keys', function() {
metadata.add('key', 'value');
metadata.remove('KEY');
assert.deepEqual(metadata.get('key'), ['value']);
assert.deepEqual(metadata.get('key'), []);
});
});
describe('#get', function() {
@ -150,8 +150,8 @@ describe('Metadata', function() {
it('gets all values associated with a key', function() {
assert.deepEqual(metadata.get('key'), ['value1', 'value2']);
});
it('does not normalize keys', function() {
assert.deepEqual(metadata.get('KEY'), []);
it('Normalizes keys', function() {
assert.deepEqual(metadata.get('KEY'), ['value1', 'value2']);
});
it('returns an empty list for non-existent keys', function() {
assert.deepEqual(metadata.get('non-existent-key'), []);

Loading…
Cancel
Save