Skip to content

Commit f259cb2

Browse files
committed
Bug 1946467 - Treat multiple commas/periods as thousands separators not as decimal points. r=daleharvey
Differential Revision: https://phabricator.services.mozilla.com/D237629
1 parent 7c000a2 commit f259cb2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

browser/components/urlbar/UrlbarProviderCalculator.sys.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,14 @@ Calculator.addNumberSystem({
504504
// Contains both a period and a comma and the comma came first
505505
// so strip the comma (ie 1,999.5).
506506
num = num.replace(/,/g, "");
507+
} else if (firstComma != -1 && num.includes(",", firstComma + 1)) {
508+
// Contains multiple commas and no periods, strip commas
509+
num = num.replace(/,/g, "");
510+
} else if (firstPeriod != -1 && num.includes(".", firstPeriod + 1)) {
511+
// Contains multiple periods and no commas, strip periods
512+
num = num.replace(/\./g, "");
507513
} else if (firstComma != -1) {
508-
// Has commas but no periods so treat comma as decimal seperator
514+
// Has a single comma and no periods, treat comma as decimal seperator
509515
num = num.replace(/,/g, ".");
510516
}
511517
return num;

browser/components/urlbar/tests/unit/test_calculator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const FORMULAS = [
3939
["1/0", "undefined"],
4040
["1/3", 0.3333333333333333],
4141
["1/(3*10^10)", "3.33333333e-11"],
42+
["1,000,000+500", 1000500],
43+
["1.000.000+500", 1000500],
4244
];
4345

4446
add_task(function test() {

0 commit comments

Comments
 (0)