Skip to content

Commit

Permalink
Merge pull request JakeChampion#156 from kruppel/kurt/header-value-st…
Browse files Browse the repository at this point in the history
…rings

Properly convert undefined/null header values to strings.
  • Loading branch information
dgraham committed Jul 19, 2015
2 parents 60c9f11 + 527a094 commit 59870bb
Show file tree
Hide file tree
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
Expand Up @@ -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')
Expand All @@ -17,7 +17,7 @@

function normalizeValue(value) {
if (typeof value !== 'string') {
value = value.toString();
value = String(value)
}
return value
}
Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 59870bb

Please sign in to comment.