Do not render links if uri is invalid
This commit is contained in:
@@ -11,6 +11,9 @@ import {RichTextTag} from '#/components/RichTextTag'
|
|||||||
import {Text, type TextProps} from '#/components/Typography'
|
import {Text, type TextProps} from '#/components/Typography'
|
||||||
|
|
||||||
const WORD_WRAP = {wordWrap: 1}
|
const WORD_WRAP = {wordWrap: 1}
|
||||||
|
// lifted from facet detection in `RichText` impl
|
||||||
|
const URL_REGEX =
|
||||||
|
/(^|\s|\()((https?:\/\/[\S]+)|((?<domain>[a-z][a-z0-9]*(\.[a-z0-9]+)+)[\S]*))/i
|
||||||
|
|
||||||
export type RichTextProps = TextStyleProp &
|
export type RichTextProps = TextStyleProp &
|
||||||
Pick<TextProps, 'selectable' | 'onLayout' | 'onTextLayout'> & {
|
Pick<TextProps, 'selectable' | 'onLayout' | 'onTextLayout'> & {
|
||||||
@@ -115,7 +118,8 @@ export function RichText({
|
|||||||
</ProfileHoverCard>,
|
</ProfileHoverCard>,
|
||||||
)
|
)
|
||||||
} else if (link && AppBskyRichtextFacet.validateLink(link).success) {
|
} else if (link && AppBskyRichtextFacet.validateLink(link).success) {
|
||||||
if (disableLinks) {
|
const isValidLink = URL_REGEX.test(link.uri)
|
||||||
|
if (!isValidLink || disableLinks) {
|
||||||
els.push(toShortUrl(segment.text))
|
els.push(toShortUrl(segment.text))
|
||||||
} else {
|
} else {
|
||||||
els.push(
|
els.push(
|
||||||
|
|||||||
Reference in New Issue
Block a user