pull/20648/head
xuzijie1995 12 months ago
parent f78a4c8aee
commit 407e16b4bb

@ -7,7 +7,7 @@ import RemarkGfm from 'remark-gfm'
import RehypeRaw from 'rehype-raw' import RehypeRaw from 'rehype-raw'
import { flow } from 'lodash-es' import { flow } from 'lodash-es'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { preprocessLaTeX, preprocessThinkTag, customUrlTransform } from './markdown-utils' import { customUrlTransform, preprocessLaTeX, preprocessThinkTag } from './markdown-utils'
import { import {
AudioBlock, AudioBlock,
CodeBlock, CodeBlock,

@ -55,38 +55,33 @@ export const preprocessThinkTag = (content: string) => {
* signal that the URI should be removed/disallowed by react-markdown. * signal that the URI should be removed/disallowed by react-markdown.
*/ */
export const customUrlTransform = (uri: string): string | undefined => { 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('#')) { if (uri.startsWith('#'))
return uri; return uri
}
if (uri.startsWith('//')) { if (uri.startsWith('//'))
return uri; return uri
}
const colonIndex = uri.indexOf(':'); const colonIndex = uri.indexOf(':')
if (colonIndex === -1) { if (colonIndex === -1)
return uri; return uri
}
const slashIndex = uri.indexOf('/'); const slashIndex = uri.indexOf('/')
const questionMarkIndex = uri.indexOf('?'); const questionMarkIndex = uri.indexOf('?')
const hashIndex = uri.indexOf('#'); const hashIndex = uri.indexOf('#')
if ( if (
(slashIndex !== -1 && colonIndex > slashIndex) || (slashIndex !== -1 && colonIndex > slashIndex) ||
(questionMarkIndex !== -1 && colonIndex > questionMarkIndex) || (questionMarkIndex !== -1 && colonIndex > questionMarkIndex) ||
(hashIndex !== -1 && colonIndex > hashIndex) (hashIndex !== -1 && colonIndex > hashIndex)
) { )
return uri; return uri
}
const scheme = uri.substring(0, colonIndex + 1).toLowerCase(); const scheme = uri.substring(0, colonIndex + 1).toLowerCase()
if (PERMITTED_SCHEME_REGEX.test(scheme)) { if (PERMITTED_SCHEME_REGEX.test(scheme))
return uri; return uri
}
return undefined; return undefined
} }
Loading…
Cancel
Save