mirror of
https://github.com/hexastack/hexabot
synced 2025-02-22 20:38:32 +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,
|
DialogProps,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { isAbsoluteUrl } from "next/dist/shared/lib/utils";
|
|
||||||
import { useEffect, FC } from "react";
|
import { useEffect, FC } from "react";
|
||||||
import { useForm, Controller } from "react-hook-form";
|
import { useForm, Controller } from "react-hook-form";
|
||||||
import { useTranslation } from "react-i18next";
|
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 { Input } from "@/app-components/inputs/Input";
|
||||||
import { ToggleableInput } from "@/app-components/inputs/ToggleableInput";
|
import { ToggleableInput } from "@/app-components/inputs/ToggleableInput";
|
||||||
import { IMenuItem, IMenuItemAttributes, MenuType } from "@/types/menu.types";
|
import { IMenuItem, IMenuItemAttributes, MenuType } from "@/types/menu.types";
|
||||||
|
import { isAbsoluteUrl } from "@/utils/URL";
|
||||||
|
|
||||||
export type MenuDialogProps = DialogProps & {
|
export type MenuDialogProps = DialogProps & {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
|
@ -29,7 +29,6 @@ export const getFromQuery = ({
|
|||||||
|
|
||||||
export const buildURL = (baseUrl: string, relativePath: string): string => {
|
export const buildURL = (baseUrl: string, relativePath: string): string => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const url = new URL(relativePath, baseUrl);
|
const url = new URL(relativePath, baseUrl);
|
||||||
|
|
||||||
return url.toString();
|
return url.toString();
|
||||||
@ -37,3 +36,18 @@ export const buildURL = (baseUrl: string, relativePath: string): string => {
|
|||||||
throw new Error(`Invalid base URL: ${baseUrl}`);
|
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