Skip to content

Commit 45ab228

Browse files
authored
Fix URLs (#356)
* Fix URLs • Sending an image URL with query parameters used to not work. • The SDK was checking the end of URL's to make sure they were an image or other media type (ie. making sure it ended in .jpeg, .mp3, etc) • Changed the SDK so that it will now remove query parameters from the end of URL's before attempting to type check the file extension * Add URL Test • Adds a test to make sure the SDK appropriately handles media URL's even if they have query parameters
1 parent e602cb2 commit 45ab228

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,12 @@ + (void)addNotificationRequest:(OSNotificationPayload*)payload
710710

711711
// Synchroneously downloads a media
712712
// On success returns bundle resource name, otherwise returns nil
713-
+ (NSString*)downloadMediaAndSaveInBundle:(NSString*)url {
713+
+ (NSString*)downloadMediaAndSaveInBundle:(NSString*)urlString {
714+
715+
let inputUrl = [NSURL URLWithString:urlString];
716+
717+
//removes any unnecessary query parameters that would break extension type checking
718+
let url = [[NSURL alloc] initWithScheme:inputUrl.scheme host:inputUrl.host path:inputUrl.path].absoluteString;
714719

715720
NSArray<NSString*>* supportedExtensions = @[@"aiff", @"wav", @"mp3", @"mp4", @"jpg", @"jpeg", @"png", @"gif", @"mpeg", @"mpg", @"avi", @"m4a", @"m4v"];
716721
NSArray* components = [url componentsSeparatedByString:@"."];

iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
#import "OneSignalClientOverrider.h"
8080
#import "OneSignalCommonDefines.h"
8181

82+
@interface OneSignalHelper (TestHelper)
83+
+ (NSString*)downloadMediaAndSaveInBundle:(NSString*)urlString;
84+
@end
85+
8286

8387
@interface UnitTests : XCTestCase
8488

@@ -1837,4 +1841,13 @@ -(void)testDelayedSubscriptionUpdate {
18371841
XCTAssertTrue(observer->last.to.subscribed);
18381842
}
18391843

1844+
// Checks to make sure that media URL's will not fail the extension-type check if they have query parameters
1845+
- (void)testHandlingMediaUrlExtensions {
1846+
let testUrl = @"https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=100";
1847+
1848+
let cacheName = [OneSignalHelper downloadMediaAndSaveInBundle:testUrl];
1849+
1850+
XCTAssertNotNil(cacheName);
1851+
}
1852+
18401853
@end

0 commit comments

Comments
 (0)