Fix misplaced '@' in RTL post meta. (#4531)
Co-authored-by: Joel <joel.garplind+github@gmail.com> Co-authored-by: Hailey <me@haileyok.com>zio/stable
parent
ea37298cdd
commit
ea7afecf28
|
@ -12,10 +12,6 @@ export function createSanitizedDisplayName(
|
||||||
if (profile.displayName != null && profile.displayName !== '') {
|
if (profile.displayName != null && profile.displayName !== '') {
|
||||||
return sanitizeDisplayName(profile.displayName)
|
return sanitizeDisplayName(profile.displayName)
|
||||||
} else {
|
} else {
|
||||||
let sanitizedHandle = sanitizeHandle(profile.handle)
|
return sanitizeHandle(profile.handle, noAt ? '' : '@')
|
||||||
if (!noAt) {
|
|
||||||
sanitizedHandle = `@${sanitizedHandle}`
|
|
||||||
}
|
|
||||||
return sanitizedHandle
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
const LEFT_TO_RIGHT_EMBEDDING = '\u202A'
|
||||||
|
const POP_DIRECTIONAL_FORMATTING = '\u202C'
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Force LTR directionality in a string.
|
||||||
|
* https://www.unicode.org/reports/tr9/#Directional_Formatting_Characters
|
||||||
|
*/
|
||||||
|
export function forceLTR(str: string) {
|
||||||
|
return LEFT_TO_RIGHT_EMBEDDING + str + POP_DIRECTIONAL_FORMATTING
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
// Regex from the go implementation
|
// Regex from the go implementation
|
||||||
// https://github.com/bluesky-social/indigo/blob/main/atproto/syntax/handle.go#L10
|
// https://github.com/bluesky-social/indigo/blob/main/atproto/syntax/handle.go#L10
|
||||||
|
import {forceLTR} from 'lib/strings/bidi'
|
||||||
|
|
||||||
const VALIDATE_REGEX =
|
const VALIDATE_REGEX =
|
||||||
/^([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])?$/
|
/^([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])?$/
|
||||||
|
|
||||||
|
@ -22,7 +24,9 @@ export function isInvalidHandle(handle: string): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sanitizeHandle(handle: string, prefix = ''): string {
|
export function sanitizeHandle(handle: string, prefix = ''): string {
|
||||||
return isInvalidHandle(handle) ? '⚠Invalid Handle' : `${prefix}${handle}`
|
return isInvalidHandle(handle)
|
||||||
|
? '⚠Invalid Handle'
|
||||||
|
: forceLTR(`${prefix}${handle}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IsValidHandle {
|
export interface IsValidHandle {
|
||||||
|
|
|
@ -32,6 +32,8 @@ interface PostMetaOpts {
|
||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NON_BREAKING_SPACE = '\u00A0'
|
||||||
|
|
||||||
let PostMeta = (opts: PostMetaOpts): React.ReactNode => {
|
let PostMeta = (opts: PostMetaOpts): React.ReactNode => {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const displayName = opts.author.displayName || opts.author.handle
|
const displayName = opts.author.displayName || opts.author.handle
|
||||||
|
@ -83,7 +85,7 @@ let PostMeta = (opts: PostMetaOpts): React.ReactNode => {
|
||||||
type="md"
|
type="md"
|
||||||
disableMismatchWarning
|
disableMismatchWarning
|
||||||
style={[pal.textLight, {flexShrink: 4}]}
|
style={[pal.textLight, {flexShrink: 4}]}
|
||||||
text={'\xa0' + sanitizeHandle(handle, '@')}
|
text={NON_BREAKING_SPACE + sanitizeHandle(handle, '@')}
|
||||||
href={profileLink}
|
href={profileLink}
|
||||||
onBeforePress={onBeforePressAuthor}
|
onBeforePress={onBeforePressAuthor}
|
||||||
anchorNoUnderline
|
anchorNoUnderline
|
||||||
|
|
Loading…
Reference in New Issue