Skip to content

JavaScript strings with NULL character are not handled properly when passed to Native Modules #12731

@nickspacek

Description

@nickspacek

Description

We are using STOMP over WebSockets to communicate with our API. On iOS everything is working as expected, on Android messages are not arriving intact. As we dug it, we discovered the trailing NULL (\0) character in the strings was not arriving.

As we sought to narrow down the cause we were able to confirm (using a sample Native Module based on the ToastAndroid module) that on Android a JavaScript string containing any NULL characters is not processed as expected; when the parameter arrives in the Java code, it has been truncated to the first occurrence of the NULL character, and the NULL character is also dropped.

For example "Hello World\0" arrives as "Hello World". "Hello\0World\0" arrives as "Hello".

Because the STOMP protocol is expecting a NULL-terminated string, it discards the WebSocket message as invalid.

Reproduction

Managed to reproduce in a fairly straightforward manner here: https://rnplay.org/apps/tkNMOQ

On Android, the element shows "Hello", presumably because the ws.send('Hello\0World\0') has been truncated. On iOS, the element shows "HelloWorld"

Solution

I'd love to understand where things are being translated from JavaScript to Java in React Native, and did start digging a bit. Ideally, NULL characters are escaped/allowed to be passed through to the Java side of things untouched, as they are on iOS.

Additional Information

  • React Native version: 0.42
  • Platform: Android
  • Operating System: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help Wanted :octocat:Issues ideal for external contributors.Issue: Author Provided ReproThis issue can be reproduced in Snack or an attached project.StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions