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

Fetch's request.integrity is coerced to the string "undefined" when undefined is explicitly passed #1176

Closed
jimsimon opened this issue Jan 25, 2022 · 2 comments · Fixed by #1177
Labels
bug Something isn't working

Comments

@jimsimon
Copy link
Contributor

jimsimon commented Jan 25, 2022

Bug Description

The following code in makeRequest coerces undefined to the string "undefined" when it's explicitly passed to the fetch options:

    // 23. If init["integrity"] exists, then set request’s integrity metadata to it.
    if ('integrity' in init) {
      request.integrity = String(init.integrity)
    }

Reproducible By

fetch('https://github.com', { integrity: undefined })

Expected Behavior

Undefined is not coerced to a string

Logs & Screenshots

Environment

Arch Linux, Node 16, server-side call (not coming from a browser)

Additional context

I ran into this while implementing a custom fetcher function for Apollo Client. Because the typings for browser/native fetch don't match unidci's fetch, I had to manually map some parameters over. It's pretty easy to workaround this by testing for a falsy value and passing an empty string if needed ({ integrity: req.integrity || ''}), but it did result in a pretty cryptic error message:

Unknown server error    Error: fetch failed

In my case, I believe my need to map stuff manually between the two implementations is actually related to #1172.

@jimsimon jimsimon added the bug Something isn't working label Jan 25, 2022
@mcollina
Copy link
Member

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@jimsimon
Copy link
Contributor Author

Sure, I'll whip something up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants