提交 f7e3e920 编写于 作者: J Jake Champion 提交者: Jake Champion

fix: Headers only accepts array which have nested array of length 2

fixes https://github.com/JakeChampion/fetch/issues/1235
上级 d8669abc
...@@ -92,6 +92,9 @@ export function Headers(headers) { ...@@ -92,6 +92,9 @@ export function Headers(headers) {
}, this) }, this)
} else if (Array.isArray(headers)) { } else if (Array.isArray(headers)) {
headers.forEach(function(header) { 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.append(header[0], header[1])
}, this) }, this)
} else if (headers) { } else if (headers) {
......
...@@ -203,6 +203,16 @@ exercise.forEach(function(exerciseMode) { ...@@ -203,6 +203,16 @@ exercise.forEach(function(exerciseMode) {
assert.equal(headers.get('Content-Type'), 'text/xml') assert.equal(headers.get('Content-Type'), 'text/xml')
assert.equal(headers.get('Breaking-Bad'), '<3') 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() { test('headers are case insensitive', function() {
var headers = new Headers({Accept: 'application/json'}) var headers = new Headers({Accept: 'application/json'})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册