Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in OneSignalAttachmentHandler trimURLSpacing #1411

Merged
merged 3 commits into from
Apr 29, 2024

Conversation

nan-li
Copy link
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

* 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
4 checks passed
@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