Skip to content

Commit d89f9b5

Browse files
committed
Added whitespace trimming to notification resources loading
* Added trim to launch url, small icon, large icon, and big picture. - This ensure they can be used even if they have spaces before or after the url. - Issue #212
1 parent 44c6682 commit d89f9b5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotification.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,17 +745,23 @@ private static Bitmap getBitmapFromURL(String location) {
745745
private static Bitmap getBitmap(String name) {
746746
if (name == null)
747747
return null;
748-
if (name.startsWith("http://") || name.startsWith("https://"))
749-
return getBitmapFromURL(name);
748+
String trimmedName = name.trim();
749+
750+
if (trimmedName.startsWith("http://") || trimmedName.startsWith("https://"))
751+
return getBitmapFromURL(trimmedName);
750752

751753
return getBitmapFromAssetsOrResourceName(name);
752754
}
753755

754756
private static int getResourceIcon(String iconName) {
755-
if (!isValidResourceName(iconName))
757+
if (iconName == null)
758+
return 0;
759+
760+
String trimmedIconName = iconName.trim();
761+
if (!isValidResourceName(trimmedIconName))
756762
return 0;
757763

758-
int notificationIcon = getDrawableId(iconName);
764+
int notificationIcon = getDrawableId(trimmedIconName);
759765
if (notificationIcon != 0)
760766
return notificationIcon;
761767

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ private static boolean openURLFromNotification(Context context, JSONArray dataAr
10611061
if (!url.contains("://"))
10621062
url = "http://" + url;
10631063

1064-
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
1064+
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url.trim()));
10651065
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET |Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
10661066
context.startActivity(intent);
10671067
urlOpened = true;

0 commit comments

Comments
 (0)