fix: [SDK-5304] reject null and empty identity strings instead of crashing - #1997
abdulraqeeb33 wants to merge 3 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
nan-li
left a comment
There was a problem hiding this comment.
We have login(externalId: string) defined as string instead of optional string in the API:
react-native-onesignal/src/index.ts
Line 122 in 11cab78
Maybe we can do the check there instead of at both bridges, like we do for addTag where we check:
if (!key || value === undefined || value === null) {
console.error('OneSignal: addTag: must include a key and a value');
return;
}
Are there other methods where devs are submitting invalid inputs that can crash?
Kotlin non-null String APIs crash when JS passes null. Empty login is invalid too. Guard both in isNonEmptyString and skip the native call. Co-authored-by: Cursor <cursoragent@cursor.com>
Good cal @nan-li - updated it in other methods as well. please check it out. |
NSLog bypasses setLogLevel. Use the same OneSignalLog error path as the rest of the iOS bridge. Co-authored-by: Cursor <cursoragent@cursor.com>
| /** Initializes the OneSignal SDK. This should be called during startup of the application. */ | ||
| export function initialize(appId: string) { | ||
| if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
| if (!isNonEmptyString(appId)) { |
There was a problem hiding this comment.
can just be !appId , similar in other places
Description
One Line Summary
Return from React Native identity string APIs when the value is null or empty instead of crashing Kotlin non-null
Stringparameters.Details
Motivation
Fixes SDK-5304. JS
nullreaches KotlinOneSignal.login(externalId: String)(and the same class of APIs:addEmail,initialize(appId)), which throwsIllegalArgumentException: Parameter specified as non-null is null. The TurboModule method is void and uncaught, so the host process dies.Empty string does not NPE, but
login("")is not a valid user id. Rejected in the same helper.Other SDKs: SDK-5309.
Scope
isNonEmptyStringin JS (null, undefined, empty). Used bylogin,initialize, email/sms/alias/language, tags, and triggers. Nativeloginalso returns on null/nil or empty.addTriggernow returns after the invalid-input log instead of still calling native. Public TS types staystring.Testing
Unit testing
src/index.test.tsandsrc/helpers.test.ts: 289 tests passed. Covers login/initialize/addEmail null and empty, helper table, and addTrigger no longer calling native.Manual testing
Not run on a device. The crash is a null argument at the bridge. Unit coverage is the JS helper. Native login guards match null/empty.
Affected code checklist
Checklist
Overview
Testing
Final pass