Skip to content

Commit

Permalink
fix: Headers only accepts array which have nested array of length 2
Browse files Browse the repository at this point in the history
fixes #1235
  • Loading branch information
JakeChampion committed Jul 18, 2023
1 parent 13117c9 commit 8f68d62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fetch.js
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Expand Up @@ -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'})
Expand Down

0 comments on commit 8f68d62

Please sign in to comment.