Skip to content

Commit 9a45633

Browse files
core: fix parsing non hierarchical uri (#2)
1 parent a01af1b commit 9a45633

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
UPCOMING
2+
-----
3+
4+
* Fixed an issue where Batch would crash when a non-hierarchical URI was parsed in a deeplink.
5+
16
2.0.0
27
-----
38

@@ -17,4 +22,4 @@
1722
1.0
1823
-----
1924

20-
* Dispatcher release.
25+
* Dispatcher release.

mixpanel-dispatcher/src/main/java/com/batch/android/dispatcher/mixpanel/MixpanelDispatcher.java

+37-27
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,22 @@ private static Map<String, Object> getInAppParams(Batch.EventDispatcher.Payload
126126

127127
String deeplink = payload.getDeeplink();
128128
if (deeplink != null) {
129-
deeplink = deeplink.trim();
130-
Uri uri = Uri.parse(deeplink);
131-
132-
String fragment = uri.getFragment();
133-
if (fragment != null && !fragment.isEmpty()) {
134-
Map<String, String> fragments = getFragmentMap(fragment);
135-
// Copy from fragment part of the deeplink
136-
copyValueFromMap(fragments, UTM_CONTENT, mixpanelParams, CONTENT);
129+
try {
130+
deeplink = deeplink.trim();
131+
Uri uri = Uri.parse(deeplink);
132+
if (uri.isHierarchical()) {
133+
String fragment = uri.getFragment();
134+
if (fragment != null && !fragment.isEmpty()) {
135+
Map<String, String> fragments = getFragmentMap(fragment);
136+
// Copy from fragment part of the deeplink
137+
copyValueFromMap(fragments, UTM_CONTENT, mixpanelParams, CONTENT);
138+
}
139+
// Copy from query parameters of the deeplink
140+
copyValueFromQuery(uri, UTM_CONTENT, mixpanelParams, CONTENT);
141+
}
142+
} catch (Exception e) {
143+
Log.e("BatchMixpanelDispatcher", "Something went wrong parsing deeplink: " + e.getLocalizedMessage());
137144
}
138-
// Copy from query parameters of the deeplink
139-
copyValueFromQuery(uri, UTM_CONTENT, mixpanelParams, CONTENT);
140145
}
141146
// Load from custom payload
142147
copyValueFromPayload(payload, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
@@ -152,24 +157,29 @@ private static Map<String, Object> getNotificationParams(Batch.EventDispatcher.P
152157

153158
String deeplink = payload.getDeeplink();
154159
if (deeplink != null) {
155-
deeplink = deeplink.trim();
156-
Uri uri = Uri.parse(deeplink);
157-
158-
String fragment = uri.getFragment();
159-
if (fragment != null && !fragment.isEmpty()) {
160-
Map<String, String> fragments = getFragmentMap(fragment);
161-
// Copy from fragment part of the deeplink
162-
copyValueFromMap(fragments, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
163-
copyValueFromMap(fragments, UTM_MEDIUM, mixpanelParams, MEDIUM);
164-
copyValueFromMap(fragments, UTM_SOURCE, mixpanelParams, SOURCE);
165-
copyValueFromMap(fragments, UTM_CONTENT, mixpanelParams, CONTENT);
166-
}
160+
try {
161+
deeplink = deeplink.trim();
162+
Uri uri = Uri.parse(deeplink);
163+
if(uri.isHierarchical()) {
164+
String fragment = uri.getFragment();
165+
if (fragment != null && !fragment.isEmpty()) {
166+
Map<String, String> fragments = getFragmentMap(fragment);
167+
// Copy from fragment part of the deeplink
168+
copyValueFromMap(fragments, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
169+
copyValueFromMap(fragments, UTM_MEDIUM, mixpanelParams, MEDIUM);
170+
copyValueFromMap(fragments, UTM_SOURCE, mixpanelParams, SOURCE);
171+
copyValueFromMap(fragments, UTM_CONTENT, mixpanelParams, CONTENT);
172+
}
167173

168-
// Copy from query parameters of the deeplink
169-
copyValueFromQuery(uri, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
170-
copyValueFromQuery(uri, UTM_MEDIUM, mixpanelParams, MEDIUM);
171-
copyValueFromQuery(uri, UTM_SOURCE, mixpanelParams, SOURCE);
172-
copyValueFromQuery(uri, UTM_CONTENT, mixpanelParams, CONTENT);
174+
// Copy from query parameters of the deeplink
175+
copyValueFromQuery(uri, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);
176+
copyValueFromQuery(uri, UTM_MEDIUM, mixpanelParams, MEDIUM);
177+
copyValueFromQuery(uri, UTM_SOURCE, mixpanelParams, SOURCE);
178+
copyValueFromQuery(uri, UTM_CONTENT, mixpanelParams, CONTENT);
179+
}
180+
} catch (Exception e) {
181+
Log.e("BatchMixpanelDispatcher", "Something went wrong parsing deeplink: " + e.getLocalizedMessage());
182+
}
173183
}
174184
// Load from custom payload
175185
copyValueFromPayload(payload, UTM_CAMPAIGN, mixpanelParams, CAMPAIGN);

0 commit comments

Comments
 (0)