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): faulty UTF-16 fast-path constraint validation

Mary dee1e70f 19731f46

+14 -7
+5
.changeset/blue-toys-hear.md
··· 1 + --- 2 + '@atcute/lexicons': patch 3 + --- 4 + 5 + fix faulty UTF-16 fast-path constraint validation
+9 -7
packages/lexicons/lexicons/lib/validations/index.ts
··· 761 761 // UTF-8 conversion can be expensive, so we're going to do some safe naive 762 762 // checks where we assume an upper-bound of the UTF-16 to UTF-8 conversion 763 763 764 - const maybeUtf8Len = input.length * 3; 764 + const utf16Len = input.length; 765 + const maybeUtf8Len = utf16Len * 3; 765 766 766 - // fail early if we're still less than minimum length 767 + // fail early if estimated upper bound is too small 767 768 if (maybeUtf8Len < minLength) { 768 769 return issue; 769 770 } 770 771 771 - // skip if we're still within maximum length 772 - if (maybeUtf8Len <= maxLength) { 772 + // skip calculation if UTF-16 length already satisfies both constraints 773 + if (utf16Len >= minLength && maybeUtf8Len <= maxLength) { 773 774 return undefined; 774 775 } 775 776 ··· 822 823 823 824 const utf16Len = input.length; 824 825 825 - // fail early if UTF-16 length is less than grapheme length 826 + // fail early if UTF-16 length is too small 826 827 if (utf16Len < minGraphemes) { 827 828 return issue; 828 829 } 829 830 830 - // skip if we're still within maximum constraint 831 - if (utf16Len <= maxGraphemes) { 831 + // if there is no minimum bounds, we can safely skip when UTF-16 is 832 + // within the maximum bounds. 833 + if (minGraphemes === 0 && utf16Len <= maxGraphemes) { 832 834 return undefined; 833 835 } 834 836