Skip to content

Commit 9724db3

Browse files
fix(datagrid-web): harden whitespace guard and locale-tag stripping
Number(" ") === 0, so the old value !== "" check silently exported whitespace strings as 0. Use value.trim() !== "" instead. hasTimeComponent matched "S" in locale tags like [$-en-US], causing date-only formats to incorrectly retain a time component. Strip bracket-delimited tokens before testing. Also documents that Mendix numeric attributes are always Big — the plain-number branch was not accidentally omitted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6ae2aea commit 9724db3

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

  • packages/pluggableWidgets/datagrid-web/src/features/data-export

packages/pluggableWidgets/datagrid-web/src/features/data-export/cell-readers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ export function excelBoolean(value: boolean): ExcelCell {
8686
}
8787

8888
function hasTimeComponent(format: string): boolean {
89-
return /[hs]/i.test(format);
89+
// Strip locale tags like [$-en-US] before checking — "S" in locale codes would otherwise match.
90+
const stripped = format.replace(/\[.*?\]/g, "");
91+
return /[hs]/i.test(stripped);
9092
}
9193

9294
function stripTime(date: Date): Date {
@@ -130,6 +132,7 @@ const readers: ReadersByType = {
130132
return excelBoolean(value);
131133
}
132134

135+
// Mendix numeric attributes always surface as Big; plain JS number is not expected here.
133136
if (value instanceof Big) {
134137
if (countSignificantDigits(value) > MAX_SAFE_SIGNIFICANT_DIGITS) {
135138
return excelString(value.toFixed(), format);
@@ -161,7 +164,7 @@ const readers: ReadersByType = {
161164
exportNumberFormat: props.exportNumberFormat
162165
});
163166

164-
if (props.exportType === "number" && value !== "") {
167+
if (props.exportType === "number" && value.trim() !== "") {
165168
const parsed = Number(value);
166169
if (!Number.isNaN(parsed)) {
167170
return excelNumber(parsed, format);

0 commit comments

Comments
 (0)