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

bug: CapacitorHTTP crashes when a header value is given as number on iOS #6202

Closed
nip3o opened this issue Jan 4, 2023 · 1 comment · Fixed by #6251
Closed

bug: CapacitorHTTP crashes when a header value is given as number on iOS #6202

nip3o opened this issue Jan 4, 2023 · 1 comment · Fixed by #6251
Labels
platform: ios type: bug A confirmed bug report

Comments

@nip3o
Copy link
Contributor

nip3o commented Jan 4, 2023

Bug Report

Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 4.6.1
@capacitor/core: 4.6.1
@capacitor/android: 4.6.1
@capacitor/ios: 4.6.1

Installed Dependencies:

@capacitor/android: not installed
@capacitor/cli: 4.6.1
@capacitor/ios: 4.6.1
@capacitor/core: 4.6.1

[success] iOS looking great! 👌

Platform(s)

Only iOS

Current Behavior

Giving the value of a HTTP header as a number rather than as string causes the exception Could not cast value of type '__NSCFNumber' (0x122864c30) to 'NSString' (0x1b7cc7fc8). to be thrown when the value is unpacked in HttpRequestHandler.

fetch("https://www.google.com/", {
    headers: {
      thisIsFine: "1337",
      thisThrowsError: 1337,
    },
  })

Expected Behavior

The numeric value should be converted to a string. This is what the Android version of the plugin does, and what the Safari browser implementation of fetch() does. One could definitely argue that header values should always be passed in as strings, but I don't think it's helpful to crash on it. Either way, plugin code should not crash internally due to user errors.

Code Reproduction

https://github.com/nip3o/capacitor-http-headers-crash

Other Technical Details

npm --version output: 6.14.17

node --version output: v14.20.0

pod --version output (iOS issues only): 1.11.3

Additional Context

I did not get a stacktrace, but the crash happens in ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift:148: let headers = (call.getObject("headers") ?? [:]) as! [String: String]

Could not cast value of type '__NSCFNumber' (0x122864c30) to 'NSString' (0x1b7cc7fc8).

@ionitron-bot
Copy link

ionitron-bot bot commented Feb 25, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: ios type: bug A confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants