Skip to content

Commit e909423

Browse files
committed
Fix Sentry JETPACK-ANDROID-1G9S and 1J82: avoid openUrl with empty url
ReaderActivityLauncher.openUrl() guards null/empty urls by reporting to Sentry and returning, so these two issues are handled reports rather than crashes. The root cause is two call sites passing empty urls, which also left the user with a button that silently does nothing. CommentDetailFragment only checked getAuthorUrl() != null, so an empty author url still wired up a dead click listener. WPWebViewActivity's "open in external browser" used mWebView.getUrl(), which is null until the first page load finishes; it now falls back to the URL_TO_LOAD extra. Fixes JETPACK-ANDROID-1G9S Fixes JETPACK-ANDROID-1J82
1 parent 3ab17e4 commit e909423

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,17 @@ private void initViewModel(WPWebViewUsageCategory webViewUsageCategory) {
348348
});
349349

350350
mViewModel.getOpenExternalBrowser().observe(this, unit -> {
351-
ReaderActivityLauncher.openUrl(WPWebViewActivity.this, mWebView.getUrl(),
352-
ReaderActivityLauncher.OpenUrlType.EXTERNAL);
351+
// Prefer the currently loaded URL, but fall back to the requested URL when the page
352+
// hasn't finished loading yet (mWebView.getUrl() is null before the first load).
353+
String urlToOpen = mWebView.getUrl();
354+
if (TextUtils.isEmpty(urlToOpen)) {
355+
Bundle extras = getIntent().getExtras();
356+
urlToOpen = extras != null ? extras.getString(URL_TO_LOAD) : null;
357+
}
358+
if (!TextUtils.isEmpty(urlToOpen)) {
359+
ReaderActivityLauncher.openUrl(WPWebViewActivity.this, urlToOpen,
360+
ReaderActivityLauncher.OpenUrlType.EXTERNAL);
361+
}
353362
});
354363

355364
mViewModel.getPreviewModeSelector().observe(this, previewModelSelectorStatus -> {

WordPress/src/main/java/org/wordpress/android/ui/comments/CommentDetailFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ private void showCommentWhenNonNull(
831831
updateStatusViews(binding, actionBinding, site, comment, note);
832832

833833
// navigate to author's blog when avatar or name clicked
834-
if (comment.getAuthorUrl() != null) {
834+
if (!TextUtils.isEmpty(comment.getAuthorUrl())) {
835835
View.OnClickListener authorListener =
836836
v -> ReaderActivityLauncher.openUrl(getActivity(), comment.getAuthorUrl());
837837
binding.imageAvatar.setOnClickListener(authorListener);

0 commit comments

Comments
 (0)