@@ -15,7 +15,7 @@ import useToasts from "hooks/useToasts";
|
||||
import { type Theme } from "types";
|
||||
import { isModKey } from "utils/keyboard";
|
||||
import { uploadFile } from "utils/uploadFile";
|
||||
import { isInternalUrl } from "utils/urls";
|
||||
import { isInternalUrl, isHash } from "utils/urls";
|
||||
|
||||
const RichMarkdownEditor = React.lazy(() =>
|
||||
import(/* webpackChunkName: "rich-markdown-editor" */ "rich-markdown-editor")
|
||||
@@ -78,7 +78,7 @@ function Editor(props: PropsWithRef) {
|
||||
const onClickLink = React.useCallback(
|
||||
(href: string, event: MouseEvent) => {
|
||||
// on page hash
|
||||
if (href[0] === "#") {
|
||||
if (isHash(href)) {
|
||||
window.location.href = href;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,27 @@ export function isInternalUrl(href: string) {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isHash(href: string) {
|
||||
if (href[0] === "#") return true;
|
||||
|
||||
try {
|
||||
const outline = new URL(window.location.href);
|
||||
const parsed = new URL(href);
|
||||
|
||||
if (
|
||||
outline.hostname === parsed.hostname &&
|
||||
outline.pathname === parsed.pathname &&
|
||||
!!parsed.hash
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
// failed to parse as url
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function decodeURIComponentSafe(text: string) {
|
||||
return text
|
||||
? decodeURIComponent(text.replace(/%(?![0-9][0-9a-fA-F]+)/g, "%25"))
|
||||
|
||||
Reference in New Issue
Block a user