Skip to content
Permalink
Browse files
Guard against null values in object parameters for bridged methods
Summary:
Handles the case when a value in an object parameter of a turbo module spec is null (even if the type is nullable).

For example, given:
```
export interface Spec extends TurboModule {
  +myFunc: ({|
    foo: ?string,
  |}) => void;
}
```
and calling `NativeModule.myFunc({foo: null})`, we see an error like:
```
JSON value '<null>' of type NSNull cannot be converted to NSString
```
Guarding against this by converting NSNull's to nils

## Changelog:

[iOS] [Fixed] - Fix crash when passing null value in object parameter of bridged method

Reviewed By: fkgozali

Differential Revision: D20591590

fbshipit-source-id: fdb90f34131427a235f2e3c99147bf1e6a9c6732
  • Loading branch information
Alexander Kawrykow authored and facebook-github-bot committed Mar 24, 2020
1 parent 8721ee0 commit 15434c7c435928a40b9cd66fe9f5d1bcdea8d954
Showing 1 changed file with 1 addition and 1 deletion.
@@ -24,7 +24,7 @@ bool RCTBridgingToBool(id value)

NSString *RCTBridgingToString(id value)
{
return [RCTConvert NSString:value];
return [RCTConvert NSString:RCTNilIfNull(value)];
}

folly::Optional<double> RCTBridgingToOptionalDouble(id value)

0 comments on commit 15434c7

Please sign in to comment.