From 79680f4d3ff8936a91b634a5fcd5aff0bf9267b4 Mon Sep 17 00:00:00 2001 From: Levin Li Date: Tue, 25 Jul 2023 21:48:25 +0800 Subject: [PATCH] Ignore malformed URL --- .../space/celestia/mobilecelestia/info/InfoFragment.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/space/celestia/mobilecelestia/info/InfoFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/info/InfoFragment.kt index b560d735..02cd6673 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/info/InfoFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/info/InfoFragment.kt @@ -40,6 +40,7 @@ import space.celestia.mobilecelestia.common.NavigationFragment import space.celestia.mobilecelestia.compose.LinkPreview import space.celestia.mobilecelestia.info.model.* import space.celestia.mobilecelestia.utils.getOverviewForSelection +import java.net.MalformedURLException import java.net.URL import javax.inject.Inject @@ -119,9 +120,13 @@ class InfoFragment : NavigationFragment.SubFragment() { id = R.dimen.common_page_medium_gap_vertical ))) } - val url = selection.webInfoURL + val urlString = selection.webInfoURL + var url: URL? = null + try { + url = URL(urlString) + } catch (ignored: MalformedURLException) {} if (hasWebInfo && url != null) { - LinkPreview(url = URL(url), modifier = rowModifier.padding(bottom = dimensionResource(id = R.dimen.common_page_medium_gap_vertical)), loadResult = { loadResult -> + LinkPreview(url = url, modifier = rowModifier.padding(bottom = dimensionResource(id = R.dimen.common_page_medium_gap_vertical)), loadResult = { loadResult -> isWebInfoLoaded = loadResult }, onClick = { finalURL -> listener?.onInfoLinkMetaDataClicked(finalURL)