This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new cc39dad34 fix(web): preserve negative numeric CSV values (#7337)
cc39dad34 is described below
commit cc39dad341ba922e9d7aa7ceea2a05c7130ff5df
Author: Yexi Xiang <[email protected]>
AuthorDate: Fri Nov 27 12:08:17 2026 +0800
fix(web): preserve negative numeric CSV values (#7337)
---
web/src/utils/download.test.ts | 9 +++++++++
web/src/utils/download.ts | 11 ++++++++++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/web/src/utils/download.test.ts b/web/src/utils/download.test.ts
index f7ab86c4b..20ddcfefc 100644
--- a/web/src/utils/download.test.ts
+++ b/web/src/utils/download.test.ts
@@ -59,6 +59,15 @@ describe('buildCsv', () => {
].join('\n'),
);
});
+
+ it('keeps numeric negative cells numeric for spreadsheet exports', () => {
+ const csv = buildCsv(
+ [{ header: 'Value', value: (row: { value: number }) => row.value }],
+ [{ value: -3.5 }],
+ );
+
+ expect(csv).toBe('"Value"\n"-3.5"');
+ });
});
describe('downloadCsv', () => {
diff --git a/web/src/utils/download.ts b/web/src/utils/download.ts
index 8ea1b7483..980c711ee 100644
--- a/web/src/utils/download.ts
+++ b/web/src/utils/download.ts
@@ -45,7 +45,16 @@ export const escapeCsvCell = (value: unknown) => {
// Prefix both formulas and literal apostrophe-prefixed formulas. The
importer removes
// exactly one protection apostrophe, so any apostrophes supplied by the
user survive a
// complete export/import round trip.
- const formulaSafeText = /^(?:[=+\-@\t\r\n]|'+[=+\-@\t\r\n])/.test(text) ?
`'${text}` : text;
+ // Numeric values have already been parsed by the application and must stay
numeric in
+ // spreadsheet exports; prefixing a negative number with an apostrophe turns
a valid metric
+ // value such as -3.5 into text. String values keep the protection because
they may be
+ // user-controlled formula input.
+ const formulaSafeText =
+ typeof value === 'number'
+ ? text
+ : /^(?:[=+\-@\t\r\n]|'+[=+\-@\t\r\n])/.test(text)
+ ? `'${text}`
+ : text;
return `"${formulaSafeText.replace(/"/g, '""')}"`;
};