From 58f0bbbb9b6f5561fa1d41ef520963bdffaa746e Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sun, 25 Jul 2021 13:43:58 -0600 Subject: [PATCH] ui(files): fix error with bad URL --- .../components/server/files/PullFileModal.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/resources/scripts/components/server/files/PullFileModal.tsx b/resources/scripts/components/server/files/PullFileModal.tsx index ecb4667d6..4dbee41fd 100644 --- a/resources/scripts/components/server/files/PullFileModal.tsx +++ b/resources/scripts/components/server/files/PullFileModal.tsx @@ -33,6 +33,14 @@ const generateFileData = (name: string): FileObject => ({ isEditable: () => false, }); +const parseURL = (url: string): string => { + try { + return new URL(url).pathname.split('/').pop() || ''; + } catch (e) { + return ''; + } +}; + export default ({ className }: WithClassname) => { const [ visible, setVisible ] = useState(false); @@ -53,7 +61,7 @@ export default ({ className }: WithClassname) => { const submit = ({ url }: Values, { setSubmitting }: FormikHelpers) => { pullFile(uuid, directory, url) - .then(() => mutate(data => [ ...data!, generateFileData(new URL(url).pathname.split('/').pop() || '') ], false)) + .then(() => mutate(data => [ ...data!, generateFileData(parseURL(url)) ], false)) .then(() => setVisible(false)) .catch(error => { console.error(error); @@ -101,7 +109,7 @@ export default ({ className }: WithClassname) => { This file will be downloaded to  /home/container/ - {values.url !== '' ? join(directory, new URL(values.url).pathname.split('/').pop() || '').substr(1) : ''} + {values.url !== '' ? join(directory, parseURL(values.url)).substr(1) : ''}