Moved key character check to before key transformation

pull/3012/head
murgatroid99 9 years ago
parent 6b8a3a74f2
commit 01a7720280
  1. 8
      src/node/src/metadata.js

@ -49,14 +49,14 @@ function Metadata() {
} }
function normalizeKey(key) { 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 key.toLowerCase();
} }
function validate(key, value) { function validate(key, value) {
if (!(/^[a-z\d-]+$/.test(key))) {
throw new Error('Metadata keys must be nonempty strings containing only ' +
'alphanumeric characters and hyphens');
}
if (_.endsWith(key, '-bin')) { if (_.endsWith(key, '-bin')) {
if (!(value instanceof Buffer)) { if (!(value instanceof Buffer)) {
throw new Error('keys that end with \'-bin\' must have Buffer values'); throw new Error('keys that end with \'-bin\' must have Buffer values');

Loading…
Cancel
Save