From e44733dd2654447906b71bf91ae2d7a5a2dfe779 Mon Sep 17 00:00:00 2001 From: nnabeyang Date: Wed, 24 Jul 2024 07:28:37 +0900 Subject: [PATCH] Fix hashtag length check to use graphemeLen for accurate length detection based on grapheme units instead of UTF-16 code points --- packages/api/src/rich-text/detection.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/api/src/rich-text/detection.ts b/packages/api/src/rich-text/detection.ts index 8d1e05521f9..528688dfd4a 100644 --- a/packages/api/src/rich-text/detection.ts +++ b/packages/api/src/rich-text/detection.ts @@ -7,6 +7,7 @@ import { TAG_REGEX, TRAILING_PUNCTUATION_REGEX, } from './util' +import { graphemeLen } from '@atproto/common-web' export type Facet = AppBskyRichtextFacet.Main @@ -85,7 +86,7 @@ export function detectFacets(text: UnicodeString): Facet[] | undefined { // strip ending punctuation and any spaces tag = tag.trim().replace(TRAILING_PUNCTUATION_REGEX, '') - if (tag.length === 0 || tag.length > 64) continue + if (tag.length === 0 || graphemeLen(tag) > 64) continue const index = match.index + leading.length