Skip to content

Commit

Permalink
Headers should not accept empty field name (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkassimo authored and bitinn committed Dec 29, 2018
1 parent 7d32932 commit 1c2f07f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/headers.js
Expand Up @@ -10,7 +10,7 @@ const invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/;

function validateName(name) {
name = `${name}`;
if (invalidTokenRegex.test(name)) {
if (invalidTokenRegex.test(name) || name === '') {
throw new TypeError(`${name} is not a legal HTTP header name`);
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Expand Up @@ -2008,6 +2008,8 @@ describe('Headers', function () {
expect(() => headers.get('Hé-y')) .to.throw(TypeError);
expect(() => headers.has('Hé-y')) .to.throw(TypeError);
expect(() => headers.set('Hé-y', 'ok')) .to.throw(TypeError);
// should reject empty header
expect(() => headers.append('', 'ok')) .to.throw(TypeError);

// 'o k' is valid value but invalid name
new Headers({ 'He-y': 'o k' });
Expand Down

0 comments on commit 1c2f07f

Please sign in to comment.