Skip to content
Snippets Groups Projects
Commit 6b8a3a74 authored by murgatroid99's avatar murgatroid99
Browse files

Normalize keys when getting and removing metadata items

parent cc248a27
No related branches found
No related tags found
No related merge requests found
...@@ -102,21 +102,23 @@ Metadata.prototype.add = function(key, value) { ...@@ -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 * @param {String} key The key to remove
*/ */
Metadata.prototype.remove = function(key) { Metadata.prototype.remove = function(key) {
key = normalizeKey(key);
if (Object.prototype.hasOwnProperty.call(this._internal_repr, key)) { if (Object.prototype.hasOwnProperty.call(this._internal_repr, key)) {
delete 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 * @param {String} key The key to get
* @return {Array.<String|Buffer>} The values associated with that key * @return {Array.<String|Buffer>} The values associated with that key
*/ */
Metadata.prototype.get = function(key) { Metadata.prototype.get = function(key) {
key = normalizeKey(key);
if (Object.prototype.hasOwnProperty.call(this._internal_repr, key)) { if (Object.prototype.hasOwnProperty.call(this._internal_repr, key)) {
return this._internal_repr[key]; return this._internal_repr[key];
} else { } else {
......
...@@ -135,10 +135,10 @@ describe('Metadata', function() { ...@@ -135,10 +135,10 @@ describe('Metadata', function() {
metadata.remove('key'); metadata.remove('key');
assert.deepEqual(metadata.get('key'), []); assert.deepEqual(metadata.get('key'), []);
}); });
it('does not normalize keys', function() { it('Normalizes keys', function() {
metadata.add('key', 'value'); metadata.add('key', 'value');
metadata.remove('KEY'); metadata.remove('KEY');
assert.deepEqual(metadata.get('key'), ['value']); assert.deepEqual(metadata.get('key'), []);
}); });
}); });
describe('#get', function() { describe('#get', function() {
...@@ -150,8 +150,8 @@ describe('Metadata', function() { ...@@ -150,8 +150,8 @@ describe('Metadata', function() {
it('gets all values associated with a key', function() { it('gets all values associated with a key', function() {
assert.deepEqual(metadata.get('key'), ['value1', 'value2']); assert.deepEqual(metadata.get('key'), ['value1', 'value2']);
}); });
it('does not normalize keys', function() { it('Normalizes keys', function() {
assert.deepEqual(metadata.get('KEY'), []); assert.deepEqual(metadata.get('KEY'), ['value1', 'value2']);
}); });
it('returns an empty list for non-existent keys', function() { it('returns an empty list for non-existent keys', function() {
assert.deepEqual(metadata.get('non-existent-key'), []); assert.deepEqual(metadata.get('non-existent-key'), []);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment