Skip to content

Commit

Permalink
Fix hashtag length check to use graphemeLen for accurate length detec…
Browse files Browse the repository at this point in the history
…tion based on grapheme units instead of UTF-16 code points
  • Loading branch information
nnabeyang committed Nov 23, 2024
1 parent 60df3fc commit e44733d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/api/src/rich-text/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TAG_REGEX,
TRAILING_PUNCTUATION_REGEX,
} from './util'
import { graphemeLen } from '@atproto/common-web'

export type Facet = AppBskyRichtextFacet.Main

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit e44733d

Please sign in to comment.