From 8b18817635fb3e2ea862317aa27bd396adcee568 Mon Sep 17 00:00:00 2001 From: Maximiliano Ibarra <6089438+Machi3mfl@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:09:47 -0300 Subject: [PATCH] Fix export formatted csv data with special characters from tables (#7048) * Scape doublequotes on export * Add sanitize to the new line character * Update CHANGELOG * Apply prettier * Apply prettier * Scape linebreak --------- Co-authored-by: Federico Rodriguez --- CHANGELOG.md | 1 + .../components/common/data-grid/data-grid-service.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cac93806..c8f3be31da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Fixed read-only users could not access to Statistics application [#7001](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7001) - Fixed no-agent-alert spawn with selected agent in agent-welcome view [#7029](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7029) - Fixed security policy exception when it contained deprecated actions [#7042](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7042) +- Fix export formatted csv data with special characters from tables [#7048](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7048) ### Removed diff --git a/plugins/main/public/components/common/data-grid/data-grid-service.ts b/plugins/main/public/components/common/data-grid/data-grid-service.ts index 35151a2f2d..bdd6cace7e 100644 --- a/plugins/main/public/components/common/data-grid/data-grid-service.ts +++ b/plugins/main/public/components/common/data-grid/data-grid-service.ts @@ -170,7 +170,12 @@ export const exportSearchToCSV = async ( if (typeof value === 'object') { return JSON.stringify(value); } - return `"${value}"`; + // Escape double quotes and handle line breaks to prevent column misalignment + return `"${value + .toString() + .replaceAll(/"/g, '""') + .replaceAll(/\r\n/g, '\\r\\n') + .replaceAll(/\n/g, '\\n')}"`; }); return parsedRow?.join(','); })