Skip to content
Merged
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
4 changes: 1 addition & 3 deletions src/node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ export function createError(errorCode: string, func = '', path = '', path2 = '',
}

export function genRndStr6(): string {
const str = (Math.random() + 1).toString(36).substring(2, 8);
if (str.length === 6) return str;
else return genRndStr6();
return Math.random().toString(36).slice(2, 8).padEnd(6, '0');
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

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

The refactored implementation changes the behavior from the original. Math.random().toString(36) can produce strings shorter than 8 characters (including the '0.' prefix), so slice(2, 8) may return fewer than 6 characters. While padEnd addresses the length issue, it introduces '0' characters that weren't present in the original recursive approach, potentially affecting uniqueness and the expected character distribution.

Suggested change
return Math.random().toString(36).slice(2, 8).padEnd(6, '0');
let str = '';
while (str.length < 6) {
str += Math.random().toString(36).slice(2);
}
return str.slice(0, 6);

Copilot uses AI. Check for mistakes.
}

export function flagsToNumber(flags: misc.TFlags | undefined): number {
Expand Down
Loading