Fix TypeError: Failed to construct 'URL': Invalid URL (#1083)
This commit is contained in:
parent
7d587c7cf8
commit
40463d526c
@ -178,7 +178,12 @@ export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, o
|
|||||||
// If [text](url) was parsed as <a> and text is not empty and not a link itself,
|
// If [text](url) was parsed as <a> and text is not empty and not a link itself,
|
||||||
// we don't render it as an image since it was probably a conscious choice to include text.
|
// we don't render it as an image since it was probably a conscious choice to include text.
|
||||||
const text = children[0]
|
const text = children[0]
|
||||||
const url = !href.startsWith('/') && new URL(href)
|
let url
|
||||||
|
try {
|
||||||
|
url = !href.startsWith('/') && new URL(href)
|
||||||
|
} catch {
|
||||||
|
// ignore invalid URLs
|
||||||
|
}
|
||||||
const internalURL = process.env.NEXT_PUBLIC_URL
|
const internalURL = process.env.NEXT_PUBLIC_URL
|
||||||
if (!!text && !/^https?:\/\//.test(text)) {
|
if (!!text && !/^https?:\/\//.test(text)) {
|
||||||
if (props['data-footnote-ref'] || typeof props['data-footnote-backref'] !== 'undefined') {
|
if (props['data-footnote-ref'] || typeof props['data-footnote-backref'] !== 'undefined') {
|
||||||
@ -191,7 +196,7 @@ export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, o
|
|||||||
</Link>
|
</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (href.startsWith('/') || url.origin === internalURL) {
|
if (href.startsWith('/') || url?.origin === internalURL) {
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
id={props.id}
|
id={props.id}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user