Skip to content

header type check bug #128

@Zaynex

Description

@Zaynex

In electron@5.x
I find an interesting bug.

image

image

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions