Skip to content

Commit

Permalink
Handle opaque URIs in PaymentAuthWebViewClient (#1428)
Browse files Browse the repository at this point in the history
`Uri#getQueryParameterNames()` throws an exception
on opaque URIs (e.g. mailto:[email protected]).
  • Loading branch information
mshafrir-stripe authored Aug 27, 2019
1 parent ae06ebe commit 7f9d1cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,15 @@ private boolean isReturnUrl(@NonNull Uri uri) {
mReturnUrl.getHost() != null &&
mReturnUrl.getHost().equals(uri.getHost());
} else {
// Skip opaque (i.e. non-hierarchical) URIs
if (uri.isOpaque()) {
return false;
}

// If the `returnUrl` is unknown, look for URIs that contain a
// `payment_intent_client_secret` or `setup_intent_client_secret`
// query parameter, and check if its values matches the given `clientSecret`
// as a query parameter.

final Set<String> paramNames = uri.getQueryParameterNames();
final String clientSecret;
if (paramNames.contains(PARAM_PAYMENT_CLIENT_SECRET)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,14 @@ public void onPageFinished_witRedirectCompleteUrl_shouldFinish() {
"https://hooks.stripe.com/redirect/complete/src_1ExLWoCRMbs6FrXfjPJRYtng");
verify(mActivity).finish();
}

@Test
public void shouldOverrideUrlLoading_withOpaqueUri_shouldNotCrash() {
final String deepLink = "mailto:[email protected]?payment_intent=pi_123&" +
"payment_intent_client_secret=pi_123_secret_456&source_type=card";
final PaymentAuthWebView.PaymentAuthWebViewClient paymentAuthWebViewClient =
new PaymentAuthWebView.PaymentAuthWebViewClient(mActivity, mProgressBar,
"pi_123_secret_456", null);
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, deepLink);
}
}

0 comments on commit 7f9d1cb

Please sign in to comment.