maybeGetInitialRouteFromIntent: check if URI data getPath() is null (flutter/engine#29766)

This commit is contained in:
Igor Cota
2021-12-16 22:09:13 +01:00
committed by GitHub
parent 897e4a51e2
commit 3ce5370e35
2 changed files with 31 additions and 7 deletions

View File

@@ -443,15 +443,17 @@ import java.util.Arrays;
private String maybeGetInitialRouteFromIntent(Intent intent) {
if (host.shouldHandleDeeplinking()) {
Uri data = intent.getData();
if (data != null && !data.getPath().isEmpty()) {
if (data != null) {
String fullRoute = data.getPath();
if (data.getQuery() != null && !data.getQuery().isEmpty()) {
fullRoute += "?" + data.getQuery();
if (fullRoute != null && !fullRoute.isEmpty()) {
if (data.getQuery() != null && !data.getQuery().isEmpty()) {
fullRoute += "?" + data.getQuery();
}
if (data.getFragment() != null && !data.getFragment().isEmpty()) {
fullRoute += "#" + data.getFragment();
}
return fullRoute;
}
if (data.getFragment() != null && !data.getFragment().isEmpty()) {
fullRoute += "#" + data.getFragment();
}
return fullRoute;
}
}
return null;

View File

@@ -598,6 +598,28 @@ public class FlutterActivityAndFragmentDelegateTest {
.pushRoute("/custom/route?query=test");
}
@Test
public void itDoesNotSendPushRouteMessageWhenOnNewIntentIsNonHierarchicalUri() {
when(mockHost.shouldHandleDeeplinking()).thenReturn(true);
// Create the real object that we're testing.
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
// --- Execute the behavior under test ---
// The FlutterEngine is set up in onAttach().
delegate.onAttach(RuntimeEnvironment.application);
Intent mockIntent = mock(Intent.class);
// mailto: URIs are non-hierarchical
when(mockIntent.getData()).thenReturn(Uri.parse("mailto:test@test.com"));
// Emulate the host and call the method
delegate.onNewIntent(mockIntent);
// Verify that the navigation channel was not given a push route message.
verify(mockFlutterEngine.getNavigationChannel(), times(0)).pushRoute("mailto:test@test.com");
}
@Test
public void itSendsPushRouteMessageWhenOnNewIntentWithQueryParameterAndFragment() {
when(mockHost.shouldHandleDeeplinking()).thenReturn(true);