Skip to content

Commit 797c2f7

Browse files
Limit number precision to 21 digits in JSONSanitizer
Addresses the TODO at line 327 by capping the number of significant digits collected during number canonicalization to 21. This aligns with standard JS number string formatting (ECMA-262) and prevents excessively long number strings in sanitized JSON. Numbers with more than 21 significant digits will have their precision truncated to 21 digits before being formatted (typically into scientific notation by subsequent logic).
1 parent 258c0e9 commit 797c2f7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CodenameOne/src/com/codename1/io/JSONSanitizer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,10 @@ private static boolean canonicalizeNumber(
324324
--nZeroesPending;
325325
}
326326

327-
// TODO: limit s to 21 digits?
328-
sanitizedJson.setCharAt(digitOutPos++, vdigit);
327+
// Limit s to 21 digits
328+
if (digitOutPos - intStart < 21) {
329+
sanitizedJson.setCharAt(digitOutPos++, vdigit);
330+
}
329331
}
330332
}
331333
}

0 commit comments

Comments
 (0)