From 79226aa8b569bccfc5e3319ed0535a031bb46474 Mon Sep 17 00:00:00 2001 From: Cal Leung Date: Wed, 2 Oct 2024 19:50:10 +0000 Subject: [PATCH] chore(runway): cherry-pick fix: Fix invalid browser url crash (#11581) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This PR fixes the crash in 7.32.0 for invalid URL in browser. The global `URL` didn't catch invalid urls gracefully, so we are using the lib `url-parser` ## **Related issues** Fixes: #11479 ## **Manual testing steps** 1. Go to browser 2. Enter `httttps://app.uniswap.org` 3. Website shows invalid url scheme 4. App doesn't crash ## **Screenshots/Recordings** ### **Before** ### **After** https://github.com/user-attachments/assets/2980c632-ed4b-48a4-976c-b1da54c590ce ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- app/components/UI/AccountRightButton/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/components/UI/AccountRightButton/index.tsx b/app/components/UI/AccountRightButton/index.tsx index 84351a1b056..4b21c8a6702 100644 --- a/app/components/UI/AccountRightButton/index.tsx +++ b/app/components/UI/AccountRightButton/index.tsx @@ -29,6 +29,7 @@ import { MetaMetricsEvents } from '../../../core/Analytics'; import { AccountOverviewSelectorsIDs } from '../../../../e2e/selectors/AccountOverview.selectors'; import { useMetrics } from '../../../components/hooks/useMetrics'; import { useNetworkInfo } from '../../../selectors/selectedNetworkController'; +import UrlParser from 'url-parse'; const styles = StyleSheet.create({ leftButton: { @@ -138,7 +139,7 @@ const AccountRightButton = ({ const currentUrl = route.params?.url; let hostname; if (currentUrl) { - hostname = new URL(currentUrl).hostname; + hostname = new UrlParser(currentUrl)?.hostname; } const { networkName, networkImageSource } = useNetworkInfo(hostname);