Skip to content

Commit

Permalink
Properly convert undefined/null header values to strings.
Browse files Browse the repository at this point in the history
kruppel committed Jun 3, 2015
1 parent 030e721 commit 527a094
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fetch.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@

function normalizeName(name) {
if (typeof name !== 'string') {
name = name.toString();
name = String(name)
}
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
throw new TypeError('Invalid character in header field name')
@@ -17,7 +17,7 @@

function normalizeValue(value) {
if (typeof value !== 'string') {
value = value.toString();
value = String(value)
}
return value
}
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -128,7 +128,9 @@ suite('Headers', function() {
test('converts field value to string on set and get', function() {
var headers = new Headers()
headers.set('Content-Type', 1)
headers.set('X-CSRF-Token', undefined);
assert.equal(headers.get('Content-Type'), '1')
assert.equal(headers.get('X-CSRF-Token'), 'undefined')
})
test('throws TypeError on invalid character in field name', function() {
assert.throws(function() { new Headers({'<Accept>': ['application/json']}) }, TypeError)

0 comments on commit 527a094

Please sign in to comment.