Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ describe('setExploreAttributeBounds', () => {
'duration:>=1.5 duration:<9'
);
});

it('writes tiny and huge bounds without exponent notation', () => {
expect(setExploreAttributeBounds('', 'value', 1e-7, 1e21)).toBe(
'value:>=0.0000001 value:<1000000000000000000000'
);
});
});
14 changes: 13 additions & 1 deletion static/app/views/explore/utils/setExploreAttributeBounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ export function setExploreAttributeBounds(
): string {
const search = new MutableSearch(query);
// `shouldEscape` is off so the comparison operators (`>=`, `<`) aren't quoted.
search.setFilterValues(attribute, [`>=${min}`, `<${max}`], false);
search.setFilterValues(
attribute,
[`>=${formatSearchNumber(min)}`, `<${formatSearchNumber(max)}`],
false
);
return search.formatString();
}

/**
* The search grammar has no exponent syntax, so `1e-7` must be written out as
* `0.0000001`.
*/
function formatSearchNumber(value: number): string {
return value.toLocaleString(undefined, {useGrouping: false, maximumFractionDigits: 20});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locale formatting breaks search numbers

High Severity

formatSearchNumber now calls toLocaleString with undefined, so the decimal separator follows the browser locale. Search grammar only accepts ASCII digits and a period, so heatmap zoom writes unparseable bounds (for example a comma) for many users.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6d43001. Configure here.

}
Loading