Skip to content

Conversation

@praveen-raj-x
Copy link

adding defensive checks for the missing nil checks on the react native code base.

resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
// Validate content dictionary
if (!content || ![content isKindOfClass:[NSDictionary class]]) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if content type changes in ios and android, we will have to update here as well. What if we move validation in android and ios sdks and make sure proper error is returned via RN as well?

NSString *contentType = content[@"type"];

// Add nil check before calling methods
if (!contentType || ![contentType isKindOfClass:[NSString class]]) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above and for others validations

}
};

const ensureString = (value: string, fallback = '') =>
Copy link

@Ahmdrza Ahmdrza Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can bypass this validation by passing wrong value as fallback param, for example, ensureString(1, 1) would return 1, even though its not a string. I think we should just return error that if value is not string, return error

const ensureString = (value: string, fallback = '') =>
typeof value === 'string' ? value : fallback;

const ensureNumber = (value: number, fallback = 0) =>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above and in other methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants