UI: Validate both org logo URLs, accept data URIs (#27160)
## For #26271  - [x] Changes file added for user-visible changes in `changes/` - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
This commit is contained in:
co-authored by
Jacob Shandling
parent
7953fe2e2c
commit
11307525d1
@@ -0,0 +1 @@
|
||||
* Add validation to both org logo URL fields, and accept data URIs as valid
|
||||
@@ -1,5 +1,7 @@
|
||||
import React, { useState } from "react";
|
||||
|
||||
import isDataURI from "validator/lib/isDataURI";
|
||||
|
||||
import Button from "components/buttons/Button";
|
||||
// @ts-ignore
|
||||
import InputField from "components/forms/fields/InputField";
|
||||
@@ -30,6 +32,9 @@ interface IOrgInfoFormErrors {
|
||||
const baseClass = "app-config-form";
|
||||
const cardClass = "org-info";
|
||||
|
||||
const validateOrgLogoURL = (url: string) =>
|
||||
isDataURI(url) || validUrl({ url, protocols: ["http", "https"] });
|
||||
|
||||
const Info = ({
|
||||
appConfig,
|
||||
handleSubmit,
|
||||
@@ -67,13 +72,17 @@ const Info = ({
|
||||
errors.org_name = "Organization name must be present";
|
||||
}
|
||||
|
||||
if (
|
||||
orgLogoURL &&
|
||||
!validUrl({ url: orgLogoURL, protocols: ["http", "https"] })
|
||||
) {
|
||||
if (orgLogoURL && !validateOrgLogoURL(orgLogoURL)) {
|
||||
errors.org_logo_url = `${orgLogoURL} is not a valid URL`;
|
||||
}
|
||||
|
||||
if (
|
||||
orgLogoURLLightBackground &&
|
||||
!validateOrgLogoURL(orgLogoURLLightBackground)
|
||||
) {
|
||||
errors.org_logo_url_light_background = `${orgLogoURL} is not a valid URL`;
|
||||
}
|
||||
|
||||
if (!orgSupportURL) {
|
||||
errors.org_support_url = `Organization support URL must be present`;
|
||||
} else if (
|
||||
|
||||
Reference in New Issue
Block a user