Make sure network plugin doesn't crash on invalid URLs

Summary: In the attached task an IPv6 address ended up in the URL send from IG. Since that URL couldn't be parsed, it crashed the network plugin. This change makes sure the plugin doesn't crash on invalid urls.

Reviewed By: cekkaewnumchai

Differential Revision: D23344503

fbshipit-source-id: c7ac2068e407a764d59e632bef1be7c4239c8c8a
This commit is contained in:
Michel Weststrate
2020-09-02 05:11:14 -07:00
committed by Facebook GitHub Bot
parent 2f7a84115c
commit cd197aeaaf
3 changed files with 10 additions and 4 deletions

View File

@@ -42,9 +42,9 @@ import {convertRequestToCurlCommand, getHeaderValue, decodeBody} from './utils';
import RequestDetails from './RequestDetails';
import {clipboard} from 'electron';
import {URL} from 'url';
import {DefaultKeyboardAction} from 'app/src/MenuBar';
import {MockResponseDialog} from './MockResponseDialog';
import {combineBase64Chunks} from './chunks';
import {DefaultKeyboardAction} from 'flipper-plugin';
const LOCALSTORAGE_MOCK_ROUTE_LIST_KEY = '__NETWORK_CACHED_MOCK_ROUTE_LIST';
@@ -599,8 +599,13 @@ function buildRow(
if (request.url == null) {
return null;
}
const url = new URL(request.url);
const domain = url.host + url.pathname;
let url: URL | undefined = undefined;
try {
url = new URL(request.url);
} catch (e) {
console.warn(`Failed to parse url: '${request.url}'`, e);
}
const domain = url ? url.host + url.pathname : '<unknown>';
const friendlyName = getHeaderValue(request.headers, 'X-FB-Friendly-Name');
const style = response && response.isMock ? mockingStyle : undefined;