From 8d413f0865c8688ec6999937557db1ce9dfc4f26 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 28 Nov 2023 17:02:25 +0100 Subject: [PATCH] :children_crossing: (fileUpload) Properly encode commas from uploaded file urls Closes #955 --- packages/embeds/js/package.json | 2 +- .../inputs/fileUpload/components/FileUploadForm.tsx | 11 +++++++++-- packages/embeds/nextjs/package.json | 2 +- packages/embeds/react/package.json | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/embeds/js/package.json b/packages/embeds/js/package.json index e4b25fa26d..9477d2bce0 100644 --- a/packages/embeds/js/package.json +++ b/packages/embeds/js/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/js", - "version": "0.2.24", + "version": "0.2.25", "description": "Javascript library to display typebots on your website", "type": "module", "main": "dist/index.js", diff --git a/packages/embeds/js/src/features/blocks/inputs/fileUpload/components/FileUploadForm.tsx b/packages/embeds/js/src/features/blocks/inputs/fileUpload/components/FileUploadForm.tsx index 1b4bd5153c..8180d9e34e 100644 --- a/packages/embeds/js/src/features/blocks/inputs/fileUpload/components/FileUploadForm.tsx +++ b/packages/embeds/js/src/features/blocks/inputs/fileUpload/components/FileUploadForm.tsx @@ -71,7 +71,7 @@ export const FileUploadForm = (props: Props) => { if (urls.length) return props.onSubmit({ label: `File uploaded`, - value: urls[0] ? encodeURI(urls[0]) : '', + value: urls[0] ? encodeUrl(urls[0]) : '', }) setErrorMessage('An error occured while uploading the file') } @@ -102,7 +102,7 @@ export const FileUploadForm = (props: Props) => { return setErrorMessage('An error occured while uploading the files') props.onSubmit({ label: `${urls.length} file${urls.length > 1 ? 's' : ''} uploaded`, - value: urls.filter(isDefined).map(encodeURI).join(', '), + value: urls.filter(isDefined).map(encodeUrl).join(', '), }) } @@ -278,3 +278,10 @@ const FileIcon = () => ( ) + +const encodeUrl = (url: string): string => { + const fileName = url.split('/').pop() + if (!fileName) return url + const encodedFileName = encodeURIComponent(fileName) + return url.replace(fileName, encodedFileName) +} diff --git a/packages/embeds/nextjs/package.json b/packages/embeds/nextjs/package.json index 108f07be9a..f285b90a01 100644 --- a/packages/embeds/nextjs/package.json +++ b/packages/embeds/nextjs/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/nextjs", - "version": "0.2.24", + "version": "0.2.25", "description": "Convenient library to display typebots on your Next.js website", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/embeds/react/package.json b/packages/embeds/react/package.json index 92cf906334..1d24fecceb 100644 --- a/packages/embeds/react/package.json +++ b/packages/embeds/react/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/react", - "version": "0.2.24", + "version": "0.2.25", "description": "Convenient library to display typebots on your React app", "main": "dist/index.js", "types": "dist/index.d.ts",