diff --git a/src/node/src/metadata.js b/src/node/src/metadata.js index a7b1ee3810d..d4a8b2669ff 100644 --- a/src/node/src/metadata.js +++ b/src/node/src/metadata.js @@ -49,14 +49,14 @@ function Metadata() { } 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(); } 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 (!(value instanceof Buffer)) { throw new Error('keys that end with \'-bin\' must have Buffer values');