diff --git a/web/app/components/base/markdown/index.tsx b/web/app/components/base/markdown/index.tsx index 28fb73653d..1e50e6745b 100644 --- a/web/app/components/base/markdown/index.tsx +++ b/web/app/components/base/markdown/index.tsx @@ -7,7 +7,7 @@ import RemarkGfm from 'remark-gfm' import RehypeRaw from 'rehype-raw' import { flow } from 'lodash-es' import cn from '@/utils/classnames' -import { preprocessLaTeX, preprocessThinkTag, customUrlTransform } from './markdown-utils' +import { customUrlTransform, preprocessLaTeX, preprocessThinkTag } from './markdown-utils' import { AudioBlock, CodeBlock, diff --git a/web/app/components/base/markdown/markdown-utils.ts b/web/app/components/base/markdown/markdown-utils.ts index 9fa7164b65..ea11e7d272 100644 --- a/web/app/components/base/markdown/markdown-utils.ts +++ b/web/app/components/base/markdown/markdown-utils.ts @@ -55,38 +55,33 @@ export const preprocessThinkTag = (content: string) => { * signal that the URI should be removed/disallowed by react-markdown. */ export const customUrlTransform = (uri: string): string | undefined => { - const PERMITTED_SCHEME_REGEX = /^(https?|ircs?|mailto|xmpp|abbr):$/i; + const PERMITTED_SCHEME_REGEX = /^(https?|ircs?|mailto|xmpp|abbr):$/i - if (uri.startsWith('#')) { - return uri; - } + if (uri.startsWith('#')) + return uri - if (uri.startsWith('//')) { - return uri; - } + if (uri.startsWith('//')) + return uri - const colonIndex = uri.indexOf(':'); + const colonIndex = uri.indexOf(':') - if (colonIndex === -1) { - return uri; - } + if (colonIndex === -1) + return uri - const slashIndex = uri.indexOf('/'); - const questionMarkIndex = uri.indexOf('?'); - const hashIndex = uri.indexOf('#'); + const slashIndex = uri.indexOf('/') + const questionMarkIndex = uri.indexOf('?') + const hashIndex = uri.indexOf('#') if ( (slashIndex !== -1 && colonIndex > slashIndex) || (questionMarkIndex !== -1 && colonIndex > questionMarkIndex) || (hashIndex !== -1 && colonIndex > hashIndex) - ) { - return uri; - } + ) + return uri - const scheme = uri.substring(0, colonIndex + 1).toLowerCase(); - if (PERMITTED_SCHEME_REGEX.test(scheme)) { - return uri; - } + const scheme = uri.substring(0, colonIndex + 1).toLowerCase() + if (PERMITTED_SCHEME_REGEX.test(scheme)) + return uri - return undefined; + return undefined } \ No newline at end of file