Skip to content

Commit

Permalink
Guard against null values in object parameters for bridged methods
Browse files Browse the repository at this point in the history
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 15434c7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Libraries/TypeSafety/RCTConvertHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 15434c7

Please sign in to comment.