Skip to content

Fix crash in OneSignalAttachmentHandler trimURLSpacing#1411

Merged
nan-li merged 3 commits intomainfrom
fix/crash_OneSignalAttachmentHandler_trimURLSpacing
Apr 29, 2024
Merged

Fix crash in OneSignalAttachmentHandler trimURLSpacing#1411
nan-li merged 3 commits intomainfrom
fix/crash_OneSignalAttachmentHandler_trimURLSpacing

Conversation

@nan-li
Copy link
Copy Markdown
Contributor

@nan-li nan-li commented Apr 18, 2024

Description

One Line Summary

Fix crash in OneSignalAttachmentHandler trimURLSpacing by checking for NSNull in addition to nil checking that is already existent.

Details

The attachment handler can have values in a dictionary be NSNull since is used to represent nil objects in collections, and we typically see NSNull when we convert JSON to Objective-C objects and the JSON contained null values.

Motivation

Scope

Checking for nullness

Testing

Unit testing

Added one unit test

Manual testing

Reproduced the crash by passing in NSNull manually.
Tested on iPhone 13 ios 17.4 by attaching an image and seeing method triggered.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

nan-li added 3 commits April 17, 2024 17:12
* The method `trimURLSpacing` is defined in both OneSignalCoreHelper and OneSignalAttachmentHandler
* Let's just use it in one place, the OneSignalCoreHelper, as this method is also used elsewhere.
* This is not testable in Swift due to type safety, making it hard to pass in NSNull
* But it is very possible for this method that expects NSString to receive NSNull due to processing a payload
* Therefore, a test file in OneSignalCoreTests is created in Objective-C
* As tests expand, these can be moved to more specific files
@nan-li nan-li changed the title Fix crash in OneSignalAttachmentHandler trimURLSpacing wip Fix crash in OneSignalAttachmentHandler trimURLSpacing Apr 18, 2024
@nan-li nan-li changed the title wip Fix crash in OneSignalAttachmentHandler trimURLSpacing Fix crash in OneSignalAttachmentHandler trimURLSpacing Apr 22, 2024
@nan-li nan-li merged commit 80ebbcc into main Apr 29, 2024
@nan-li nan-li deleted the fix/crash_OneSignalAttachmentHandler_trimURLSpacing branch April 29, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [OneSignalAttachmentHandler trimURLSpacing:] crash

3 participants