1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-16 02:45:31 +02:00

fix(backend): ULIDを正しく処理できない問題を修正 (#17310)

fix(backend): fix parseUlidFull to correctly handle Crockford Base32 chars W/X/Y/Z
This commit is contained in:
mq1
2026-04-15 09:02:43 +09:00
committed by GitHub
parent c9c6ef2772
commit 5dc508346c
2 changed files with 50 additions and 2 deletions

View File

@@ -5,12 +5,19 @@
// Crockford's Base32
// https://github.com/ulid/spec#encoding
import { parseBigInt32 } from '@/misc/bigint.js';
const CHARS = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
export const ulidRegExp = /^[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$/;
function parseBigIntCrockford(str: string): bigint {
let result = 0n;
for (let i = 0; i < str.length; i++) {
result = result * 32n + BigInt(CHARS.indexOf(str[i]));
}
return result;
}
function parseBase32(timestamp: string) {
let time = 0;
for (let i = 0; i < timestamp.length; i++) {
@@ -26,6 +33,6 @@ export function parseUlid(id: string): { date: Date; } {
export function parseUlidFull(id: string): { date: number; additional: bigint; } {
return {
date: parseBase32(id.slice(0, 10)),
additional: parseBigInt32(id.slice(10, 26)),
additional: parseBigIntCrockford(id.slice(10, 26)),
};
}