From 6233d2b6a9a44827cdee52e4a05c4f66506a023f Mon Sep 17 00:00:00 2001 From: Aine Date: Fri, 25 Oct 2024 11:48:34 +0300 Subject: [PATCH 1/2] Sanitize CSV on import --- src/components/ImportFeature.tsx | 11 +++++++++++ src/components/LoginFormBox.tsx | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/ImportFeature.tsx b/src/components/ImportFeature.tsx index f5e1b305..ce51fa4e 100644 --- a/src/components/ImportFeature.tsx +++ b/src/components/ImportFeature.tsx @@ -121,6 +121,7 @@ const FilePicker = () => { const verifyCsv = ({ data, meta, errors }: ParseResult, { setValues, setStats, setError }) => { /* First, verify the presence of required fields */ + meta.fields = meta.fields?.map(f => f.trim().toLowerCase()); const missingFields = expectedFields.filter(eF => !meta.fields?.find(mF => eF === mF)); if (missingFields.length > 0) { @@ -147,6 +148,15 @@ const FilePicker = () => { }; const errorMessages = errors.map(e => e.message); + // sanitize the data first + data = data.map(line => { + const newLine = {} as ImportLine; + for (const [key, value] of Object.entries(line)) { + newLine[key.trim().toLowerCase()] = value; + } + return newLine; + }); + // process the data data.forEach((line, idx) => { if (line.user_type === undefined || line.user_type === "") { stats.user_types.default++; @@ -173,6 +183,7 @@ const FilePicker = () => { line[f] = true; // we need true booleans instead of strings } else { if (line[f] !== "false" && line[f] !== "") { + console.log("invalid value", line[f], "for field " + f + " in row " + idx); errorMessages.push( translate("import_users.error.invalid_value", { field: f, diff --git a/src/components/LoginFormBox.tsx b/src/components/LoginFormBox.tsx index 6d12a594..859f1c9f 100644 --- a/src/components/LoginFormBox.tsx +++ b/src/components/LoginFormBox.tsx @@ -13,7 +13,7 @@ const LoginFormBox = styled(Box)(({ theme }) => ({ backgroundSize: "cover", [`& .card`]: { - maxWidth: "30rem", + width: "30rem", marginTop: "6rem", marginBottom: "6rem", }, From 88cea2d5e3a51a0e2350136926e99be0e13086ee Mon Sep 17 00:00:00 2001 From: Aine Date: Fri, 25 Oct 2024 11:52:10 +0300 Subject: [PATCH 2/2] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 399d1a89..8f6674d3 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ The following changes are already implemented: * [Add user profile to the top menu](https://github.com/etkecc/synapse-admin/pull/80) * [Enable visual customization](https://github.com/etkecc/synapse-admin/pull/81) * [Fix room state events display](https://github.com/etkecc/synapse-admin/pull/100) +* [Sanitize CSV on import](https://github.com/etkecc/synapse-admin/pull/101) _the list will be updated as new changes are added_