header type check bug
- Dominant language
- JavaScript
- Stars
- 953
- Forks
- 164
- PR merge metrics
- No merged PRs in 30d
Description
In `electron@5.x`
I find an interesting bug.


I set headers with object, but the object type gave `Map`, so the header think it's not an object
```
header: function (field, value) {
if (is(field).a(Object)) {
for (var key in field) {
if (Object.prototype.hasOwnProperty.call(field, key)) {
$this.header(key, field[key])
}
}
return $this
}
var existingHeaderName = $this.hasHeader(field)
$this.options.headers[existingHeaderName || field] = value
return $this
},
```
see the error stack:
```
name.toLowerCase is not a function
at Object.hasHeader (/Users/xiwz/ynote/electron-sdk/example/node_modules/unirest/index.js:93:21)
at Object.header (/Users/xiwz/ynote/electron-sdk/example/node_modules/unirest/index.js:198:40)
```
But actually I send the object
```
{
'Content-Type': '',
'Cookie': ''
}
```
I think this bug belongs to electron.It changed the Object default behavior. But `unirest` type check is unsafe.
I wonder if you would like to improve it ? I am willing to send a PR.
My solution:
```
if (check.prototype) check = Object.prototype.toString.call(check.prototype).slice(8, -1).toLowerCase()
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Inspect the header and hasHeader entry points shown in unirest/index.js at lines 93 and 198, then reproduce the object-header case under electron@5.x. Done means object headers such as Content-Type and Cookie no longer cause the name.toLowerCase error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- electron, javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100