diff --git a/fetch.js b/fetch.js index c7775afe..9c198c37 100644 --- a/fetch.js +++ b/fetch.js @@ -92,6 +92,9 @@ export function Headers(headers) { }, this) } else if (Array.isArray(headers)) { headers.forEach(function(header) { + if (header.length != 2) { + throw new TypeError('Headers constructor: expected name/value pair to be length 2, found' + header.length) + } this.append(header[0], header[1]) }, this) } else if (headers) { diff --git a/test/test.js b/test/test.js index 8508610b..e19a9841 100644 --- a/test/test.js +++ b/test/test.js @@ -203,6 +203,16 @@ exercise.forEach(function(exerciseMode) { assert.equal(headers.get('Content-Type'), 'text/xml') assert.equal(headers.get('Breaking-Bad'), '<3') + assert.throws(function() { + new Headers([ + ['Content-Type'], + ]) + }, TypeError) + assert.throws(function() { + new Headers([ + ['Content-Type', 'a', 'b'], + ]) + }, TypeError) }) test('headers are case insensitive', function() { var headers = new Headers({Accept: 'application/json'})