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]: Sending TypedArray as fetch body gets JSON.stringified #7473

Closed
1 of 3 tasks
marcelklehr opened this issue May 20, 2024 · 7 comments · Fixed by #7546
Closed
1 of 3 tasks

[Bug]: Sending TypedArray as fetch body gets JSON.stringified #7473

marcelklehr opened this issue May 20, 2024 · 7 comments · Fixed by #7546
Labels
plugin: http type: bug A confirmed bug report

Comments

@marcelklehr
Copy link

Capacitor Version

Latest Dependencies:

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

Installed Dependencies:

@capacitor/cli: 5.7.5
@capacitor/core: 5.7.5
@capacitor/android: 5.7.5
@capacitor/ios: 5.5.1

[success] Android looking great! 👌
[error] Xcode is not installed

Other API Details

npm --version
10.7.0

node --version
v20.9.0

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

sending a POST via fetch with a UInt8Array as body results in the TypedArray getting stringified as JSON.

callback: 40428488, pluginId: CapacitorHttp, methodName: request, methodData: {"url":"https://github.com/marcelklehr/test.git/git-upload-pack","method":"POST","data":{"0":48,"1":48,"2":56,"3":....

Expected Behavior

The binary data sould be sent unchanged.

Project Reproduction

https://github.com/floccusaddon/floccus

Additional Information

No response

@jcesarmobile
Copy link
Member

please, provide a sample app that reproduces the issue, not a full app with no indications about how to run or reproduce

@jcesarmobile jcesarmobile added the needs reply needs reply from the user label May 21, 2024
@ionitron-bot ionitron-bot bot removed the triage label May 21, 2024
@marcelklehr
Copy link
Author

@Ionitron Ionitron removed the needs reply needs reply from the user label May 21, 2024
@jcesarmobile jcesarmobile added type: bug A confirmed bug report plugin: http labels May 21, 2024
Copy link

ionitron-bot bot commented May 21, 2024

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

@marcelklehr

This comment was marked as off-topic.

@faan11
Copy link

faan11 commented Jun 17, 2024

This is how it works from my understanding:

From this analysis, all platforms should be affected by this bug since the convertBody function is shared by ios, android and web.
In my opinion, the solution depends on the body type:

  • if the body is a integer, the convertbody function should detect that the value is an integer. The platform implementation should handle integer values as well.
  • if the body is a json, we should use json.Stringify instead of the common toString method in the platform implementation side.

In both cases, a new function is needed to write mixed data (string+integer) to the outputstream (like writeRequestBody does for string).

Please correct me if I said something wrong. I hope this might help to solve this issue.

@jongbonga

This comment was marked as off-topic.

Copy link

ionitron-bot bot commented Aug 8, 2024

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 Aug 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
plugin: http type: bug A confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants