a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm
101
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(lexicons): mark generic URIs over 8192 UTF-8 characters as invalid

Mary 7b590bd7 aafe1538

+34 -1
+5
.changeset/red-monkeys-care.md
··· 1 + --- 2 + '@atcute/lexicons': patch 3 + --- 4 + 5 + mark generic URIs over 8192 UTF-8 characters as invalid
+29 -1
packages/lexicons/lexicons/lib/syntax/uri.ts
··· 1 + import { getUtf8Length } from '../validations/utils.js'; 2 + 1 3 /** 2 4 * represents a generic URI 3 5 */ ··· 7 9 8 10 // #__NO_SIDE_EFFECTS__ 9 11 export const isGenericUri = (input: unknown): input is GenericUri => { 10 - return typeof input === 'string' && input.length >= 3 && URI_RE.test(input); 12 + if (typeof input !== 'string') { 13 + return false; 14 + } 15 + 16 + const MIN_LENGTH = 3; 17 + const MAX_LENGTH = 8192; 18 + 19 + const utf16Len = input.length; 20 + const maybeUtf8Len = utf16Len * 3; 21 + 22 + // fail early if estimated upper bound is too small 23 + if (maybeUtf8Len < MIN_LENGTH) { 24 + return false; 25 + } 26 + 27 + // skip calculation if UTF-16 length already satisfies both constraints 28 + if (utf16Len >= MIN_LENGTH && maybeUtf8Len <= MAX_LENGTH) { 29 + return URI_RE.test(input); 30 + } 31 + 32 + const utf8Len = getUtf8Length(input); 33 + 34 + if (utf8Len < MIN_LENGTH || utf8Len > MAX_LENGTH) { 35 + return false; 36 + } 37 + 38 + return URI_RE.test(input); 11 39 };