Fix Text truncation at NULL character on iOS and Android (#24129) - #57906
Closed
kulkarni-rohan wants to merge 1 commit into
Closed
Fix Text truncation at NULL character on iOS and Android (#24129)#57906kulkarni-rohan wants to merge 1 commit into
kulkarni-rohan wants to merge 1 commit into
Conversation
…t#24129) Fixes react#24129 where <Text>{'Hello \u0000 World'}</Text> renders as 'Hello' truncated. Root cause: JS String preserves \u0000, but iOS stringWithUTF8String: and stringWithCString: and Android NewStringUTF use C-string NUL-terminated APIs that stop at embedded \0. Fix: Replace with length-aware conversions: - iOS: initWithBytes:length:encoding: (same as correct FollyConvert.mm pattern and MapBufferBuilder memcpy) - Android: convert UTF-8 std::string with size to UTF-16 via rt.utf16() + NewString, and reverse via GetStringChars + GetStringLength + createFromUtf16 Covers all surfaces (Text, TextInput, any TurboModule string param) across Fabric and old arch. [GENERAL] [FIXED] - Fix Text truncation when string contains NULL character \u0000 (react#24129)
|
@fabriziocucci has imported this pull request. If you are a Meta employee, you can view this in D115707536. |
|
@fabriziocucci merged this pull request in 5906cfb. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #24129
Summary:
Problem:
<Text>{'Hello \u0000 World'}</Text>renders as "Hello" (truncated at \u0000). Does NOT reproduce when Debug JS Remotely (JSON preserves \u0000), but reproduces in production Hermes+Fabric on iOS and Android.Root cause: JS String preserves \u0000 (length includes it), C++ std::string from JSI utf8() also preserves via size. Truncation happens at platform bridge where C-string NUL-terminated APIs are used:
Fix (4 files, ~10 lines, no new API): Replace C-string APIs with length-aware [[NSString alloc] initWithBytes:data length:size encoding:NSUTF8StringEncoding] (same as existing correct pattern in FollyConvert.mm:31 and MapBufferBuilder.cpp) and Android convertUTF8ToUTF16 + NewString(jchar*, len) + assign(jsChars, GetStringUTFLength()). All surfaces (Text, TextInput, accessibility, TurboModule params) fixed at once because shared converters are fixed.
Changelog:
[GENERAL] [FIXED] - Fix Text truncation when string contains NULL character \u0000 (#24129)
Test Plan:
Reproduction (RNTester):
Commands:
Closes #24129