You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by en...@apache.org on 2026/09/01 13:50:13 UTC
(superset) branch enxdev/fix/explore-count-metric updated: fix(datasets): trim d3format before validating percent spec
This is an automated email from the ASF dual-hosted git repository.
EnxDev pushed a commit to branch enxdev/fix/explore-count-metric
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/enxdev/fix/explore-count-metric by this push:
new 99f1e6a2898 fix(datasets): trim d3format before validating percent spec
99f1e6a2898 is described below
commit 99f1e6a2898752a188d03a5f5bd774be39bc5014
Author: Enzo Martellucci <en...@gmail.com>
AuthorDate: Tue Sep 1 15:49:42 2026 +0200
fix(datasets): trim d3format before validating percent spec
NumberFormatterRegistry.get() trims the stored format string before
parsing it at render time, so isPercentD3Format must trim too or a
value like ".0% " (trailing whitespace) renders as an unwarned
percent on a COUNT metric.
Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
.../components/DatasourceEditor/DatasourceEditor.tsx | 8 ++++----
.../tests/DatasourceEditorMetricFormatWarning.test.tsx | 11 +++++------
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx b/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx
index 061263d8c0b..394806b1716 100644
--- a/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx
+++ b/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx
@@ -830,15 +830,15 @@ const ResultTable =
// D3's '%' and 'p' types both multiply by 100; parsed via d3-format's own
// grammar so garbage like "foo%" is rejected rather than matched by suffix.
-// The stored value is validated untrimmed because getNumberFormatter formats
-// it untrimmed at render time; trimming here could flag a format (e.g. one
-// with trailing whitespace) as valid when the renderer's own parse rejects it.
+// The stored value is trimmed before parsing because
+// NumberFormatterRegistry.get() trims it the same way before rendering, so
+// this check agrees with what the renderer actually sees.
export const isPercentD3Format = (d3format?: string): boolean => {
if (!d3format) {
return false;
}
try {
- const { type } = formatSpecifier(d3format);
+ const { type } = formatSpecifier(d3format.trim());
return type === '%' || type === 'p';
} catch {
return false;
diff --git a/superset-frontend/src/components/Datasource/components/DatasourceEditor/tests/DatasourceEditorMetricFormatWarning.test.tsx b/superset-frontend/src/components/Datasource/components/DatasourceEditor/tests/DatasourceEditorMetricFormatWarning.test.tsx
index ce021b85c5e..255b63e57eb 100644
--- a/superset-frontend/src/components/Datasource/components/DatasourceEditor/tests/DatasourceEditorMetricFormatWarning.test.tsx
+++ b/superset-frontend/src/components/Datasource/components/DatasourceEditor/tests/DatasourceEditorMetricFormatWarning.test.tsx
@@ -113,12 +113,11 @@ test('isPercentD3Format accepts only a valid D3 percent/p spec', () => {
expect(isPercentD3Format(undefined)).toBe(false);
});
-// getNumberFormatter formats the stored value untrimmed at render time, so
-// this must agree rather than accept a format the renderer then rejects.
-// Trailing whitespace is invalid D3 format syntax and must not be trimmed
-// away before validating.
-test('isPercentD3Format does not trim, matching untrimmed render-time parsing', () => {
- expect(isPercentD3Format('.0% ')).toBe(false);
+// NumberFormatterRegistry.get() trims the stored value before parsing it at
+// render time, so this must trim too rather than reject a format the
+// renderer accepts.
+test('isPercentD3Format trims, matching render-time parsing', () => {
+ expect(isPercentD3Format('.0% ')).toBe(true);
});
// A '%' format is valid syntax, so it never hits the "Invalid format" fallback.