Replaced toLowerCase with local-insensitive downcasing function

This commit is contained in:
murgatroid99 2015-08-20 15:52:57 -07:00
parent d731161616
commit 79fa8dbad1
1 changed files with 8 additions and 1 deletions

View File

@ -48,12 +48,19 @@ function Metadata() {
this._internal_repr = {};
}
function downcaseString(str) {
var capitals = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var lowercase = 'abcdefghijklmnopqrstuvwxyz';
var charMap = _.zipObject(capitals, lowercase);
return str.replace(/[A-Z]/g, _.curry(_.get)(charMap));
}
function normalizeKey(key) {
if (!(/^[A-Za-z\d-]+$/.test(key))) {
throw new Error('Metadata keys must be nonempty strings containing only ' +
'alphanumeric characters and hyphens');
}
return key.toLowerCase();
return downcaseString(key);
}
function validate(key, value) {