Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

header type check bug #128

Open
Zaynex opened this issue Nov 14, 2019 · 0 comments
Open

header type check bug #128

Zaynex opened this issue Nov 14, 2019 · 0 comments

Comments

@Zaynex
Copy link

Zaynex commented Nov 14, 2019

In [email protected]
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant