Skip to content

Commit

Permalink
Fix crash when an IAM click action does not have an id
Browse files Browse the repository at this point in the history
Cherry-pick of #1248

If an In App Message built using HTML is created improperly it can send a click action with a nil id to the SDK. This results in a crash.
  • Loading branch information
emawby committed Aug 10, 2023
1 parent 6c0cda3 commit 752fcdd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,10 @@ - (void)sendClickRESTCall:(OSInAppMessageInternal *)message withAction:(OSInAppM
// Handles body, button, or image clicks
if (![self isClickAvailable:message withClickId:clickId])
return;
if (!clickId) {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:@"sendClickRESTCall:withAction: call could not be made because the click action does not have an id."];
return;
}
// Add clickId to clickedClickIds
[self.clickedClickIds addObject:clickId];
// Track clickId per IAM
Expand Down
26 changes: 26 additions & 0 deletions iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,32 @@ - (void)testIAMClickedLaunchesAPIRequest {
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequestType, NSStringFromClass([OSRequestInAppMessageClicked class]));
}

- (void)testIAMClickWithNoIDLogsError {
let message = [OSInAppMessageTestHelper testMessageJsonWithTriggerPropertyName:OS_DYNAMIC_TRIGGER_KIND_SESSION_TIME withId:@"test_id1" withOperator:OSTriggerOperatorTypeLessThan withValue:@10.0];

let registrationResponse = [OSInAppMessageTestHelper testRegistrationJsonWithMessages:@[message]];

// the trigger should immediately evaluate to true and should
// be shown once the SDK is fully initialized.
[OneSignalClientOverrider setMockResponseForRequest:NSStringFromClass([OSRequestRegisterUser class]) withResponse:registrationResponse];

[UnitTestCommonMethods initOneSignal_andThreadWait];

// the message should now be displayed
// simulate a button press (action) on the inapp message with a nil id
let action = [OSInAppMessageAction new];
action.clickType = @"button";
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
action.clickId = nil;
#pragma GCC diagnostic pop
let testMessage = [OSInAppMessageInternal instanceWithJson:message];

[OSMessagingController.sharedInstance messageViewDidSelectAction:testMessage withAction:action];
// The action should not send a request due to the nil id but it should not crash
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequestType, NSStringFromClass([OSRequestRegisterUser class]));
}

- (void)testIAMClickedLaunchesOutcomeAPIRequest {
[self setOutcomesParamsEnabled];

Expand Down

0 comments on commit 752fcdd

Please sign in to comment.