mirror of
https://github.com/hexastack/hexabot
synced 2025-02-22 04:17:48 +00:00
Merge pull request #73 from devamitranjan/FIX_ISSUE_72
fix: improve error handling for invalid URL submission
This commit is contained in:
commit
3110c6a5e5
@ -14,7 +14,6 @@ import {
|
||||
DialogProps,
|
||||
MenuItem,
|
||||
} from "@mui/material";
|
||||
import { isAbsoluteUrl } from "next/dist/shared/lib/utils";
|
||||
import { useEffect, FC } from "react";
|
||||
import { useForm, Controller } from "react-hook-form";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@ -26,6 +25,7 @@ import { ContentItem } from "@/app-components/dialogs/layouts/ContentItem";
|
||||
import { Input } from "@/app-components/inputs/Input";
|
||||
import { ToggleableInput } from "@/app-components/inputs/ToggleableInput";
|
||||
import { IMenuItem, IMenuItemAttributes, MenuType } from "@/types/menu.types";
|
||||
import { isAbsoluteUrl } from "@/utils/URL";
|
||||
|
||||
export type MenuDialogProps = DialogProps & {
|
||||
open: boolean;
|
||||
|
@ -29,7 +29,6 @@ export const getFromQuery = ({
|
||||
|
||||
export const buildURL = (baseUrl: string, relativePath: string): string => {
|
||||
try {
|
||||
|
||||
const url = new URL(relativePath, baseUrl);
|
||||
|
||||
return url.toString();
|
||||
@ -37,3 +36,18 @@ export const buildURL = (baseUrl: string, relativePath: string): string => {
|
||||
throw new Error(`Invalid base URL: ${baseUrl}`);
|
||||
}
|
||||
};
|
||||
|
||||
export const isAbsoluteUrl = (value: string = ""): boolean => {
|
||||
try {
|
||||
const url = new URL(value);
|
||||
const hostnameParts = url.hostname.split(".");
|
||||
|
||||
return (
|
||||
(url.protocol === "http:" || url.protocol === "https:") &&
|
||||
hostnameParts.length > 1 &&
|
||||
hostnameParts[hostnameParts.length - 1].length > 1
|
||||
);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user