1 Commits
Author SHA1 Message Date
Yash SinghandBandhan Majumder 1599dfd515 fix: zero-pad username suggestion suffix consistently (#29571)
generateUsernameSuggestion built its numeric suffix with
String(rand).padStart(4 - rand.toString().length, "0"). padStart's first
argument is the target total length, not the number of pad characters, so the
expression only padded single-digit numbers: rand=1 became "001" but rand=42
became "42" and rand=999 stayed "999". Suggested usernames therefore had
inconsistent suffix widths, and the magic 4 didn't match the 3-wide output the
existing test pins ("johnny001").

Pull the suffix into a small helper that always pads to 3 digits, so collisions
and the returned value share one definition and every suggestion is uniformly
zero-padded. Add unit tests for the first-attempt path and for two- and
three-digit suffixes; the two-digit case fails on the old code.

Co-authored-by: Bandhan Majumder <133476557+bandhan-majumder@users.noreply.github.com>
2026-06-19 05:37:42 +00:00