Bluesky app fork with some witchin' additions 💫

Fix misplaced '@' in RTL post meta. (#4531)

Co-authored-by: Joel <joel.garplind+github@gmail.com>
Co-authored-by: Hailey <me@haileyok.com>

authored by

Joel
Joel
Hailey
and committed by
GitHub
ea7afecf ea37298c

+19 -7
+1 -5
src/lib/moderation/create-sanitized-display-name.ts
··· 12 12 if (profile.displayName != null && profile.displayName !== '') { 13 13 return sanitizeDisplayName(profile.displayName) 14 14 } else { 15 - let sanitizedHandle = sanitizeHandle(profile.handle) 16 - if (!noAt) { 17 - sanitizedHandle = `@${sanitizedHandle}` 18 - } 19 - return sanitizedHandle 15 + return sanitizeHandle(profile.handle, noAt ? '' : '@') 20 16 } 21 17 }
+10
src/lib/strings/bidi.ts
··· 1 + const LEFT_TO_RIGHT_EMBEDDING = '\u202A' 2 + const POP_DIRECTIONAL_FORMATTING = '\u202C' 3 + 4 + /* 5 + * Force LTR directionality in a string. 6 + * https://www.unicode.org/reports/tr9/#Directional_Formatting_Characters 7 + */ 8 + export function forceLTR(str: string) { 9 + return LEFT_TO_RIGHT_EMBEDDING + str + POP_DIRECTIONAL_FORMATTING 10 + }
+5 -1
src/lib/strings/handles.ts
··· 1 1 // Regex from the go implementation 2 2 // https://github.com/bluesky-social/indigo/blob/main/atproto/syntax/handle.go#L10 3 + import {forceLTR} from 'lib/strings/bidi' 4 + 3 5 const VALIDATE_REGEX = 4 6 /^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/ 5 7 ··· 22 24 } 23 25 24 26 export function sanitizeHandle(handle: string, prefix = ''): string { 25 - return isInvalidHandle(handle) ? '⚠Invalid Handle' : `${prefix}${handle}` 27 + return isInvalidHandle(handle) 28 + ? '⚠Invalid Handle' 29 + : forceLTR(`${prefix}${handle}`) 26 30 } 27 31 28 32 export interface IsValidHandle {
+3 -1
src/view/com/util/PostMeta.tsx
··· 32 32 style?: StyleProp<ViewStyle> 33 33 } 34 34 35 + const NON_BREAKING_SPACE = '\u00A0' 36 + 35 37 let PostMeta = (opts: PostMetaOpts): React.ReactNode => { 36 38 const pal = usePalette('default') 37 39 const displayName = opts.author.displayName || opts.author.handle ··· 83 85 type="md" 84 86 disableMismatchWarning 85 87 style={[pal.textLight, {flexShrink: 4}]} 86 - text={'\xa0' + sanitizeHandle(handle, '@')} 88 + text={NON_BREAKING_SPACE + sanitizeHandle(handle, '@')} 87 89 href={profileLink} 88 90 onBeforePress={onBeforePressAuthor} 89 91 anchorNoUnderline