From 2dc8a0c355e5c4257e26ff967d297124eaf6d6c5 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 10 Jan 2023 21:11:04 -0300 Subject: [PATCH] tweak on yup validation --- app/lib/methods/helpers/image.ts | 4 ++-- app/lib/methods/helpers/url.ts | 11 ----------- app/views/ChangeAvatarView/AvatarUrl.tsx | 4 ++-- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/app/lib/methods/helpers/image.ts b/app/lib/methods/helpers/image.ts index 0f89ac3fe..0935f7615 100644 --- a/app/lib/methods/helpers/image.ts +++ b/app/lib/methods/helpers/image.ts @@ -1,7 +1,7 @@ // Fast Image can't render a svg image from a uri yet, because of that we aren't test the svg within the RegEx -export const regExpUrlImage = new RegExp( +export const regExpImageType = new RegExp( '.(jpg|jpeg|png|webp|avif|gif|tiff)' + // type of the URL '(\\?[;&a-z\\d%_.~+=-]*)?', 'i' // query string ); -export const isImage = (url: string) => regExpUrlImage.test(url); +export const isImage = (url: string) => regExpImageType.test(url); diff --git a/app/lib/methods/helpers/url.ts b/app/lib/methods/helpers/url.ts index 0370e33d3..efe675b7e 100644 --- a/app/lib/methods/helpers/url.ts +++ b/app/lib/methods/helpers/url.ts @@ -1,5 +1,3 @@ -import fetch from './fetch'; - export const isValidURL = (url: string): boolean => { const pattern = new RegExp( '^(https?:\\/\\/)?' + // protocol @@ -15,12 +13,3 @@ export const isValidURL = (url: string): boolean => { // Use checkUseSsl: false only if server url starts with http:// export const isSsl = (url: string): boolean => !/http:\/\//.test(url); - -export const isValidURLRequest = async (url: string) => { - try { - const result = await fetch(url); - return result.status === 200; - } catch { - return false; - } -}; diff --git a/app/views/ChangeAvatarView/AvatarUrl.tsx b/app/views/ChangeAvatarView/AvatarUrl.tsx index aff2b3913..c709403fd 100644 --- a/app/views/ChangeAvatarView/AvatarUrl.tsx +++ b/app/views/ChangeAvatarView/AvatarUrl.tsx @@ -5,10 +5,10 @@ import { yupResolver } from '@hookform/resolvers/yup'; import I18n from '../../i18n'; import { ControlledFormTextInput } from '../../containers/TextInput'; -import { regExpUrlImage } from '../../lib/methods/helpers'; +import { regExpImageType } from '../../lib/methods/helpers'; const schema = yup.object().shape({ - avatarUrl: yup.string().matches(regExpUrlImage).required() + avatarUrl: yup.string().url().matches(regExpImageType).required() }); interface ISubmit {