From 435d259b65ca110065a96581c1d568fb3ddd205d Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Tue, 3 Dec 2019 12:30:33 -0300 Subject: [PATCH] 15856: Adds name validation to projects and collection edit/create dialogs. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/components/warning/warning.tsx | 3 ++- src/validators/valid-name.tsx | 14 ++++++++++++++ src/validators/validators.tsx | 5 +++-- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/validators/valid-name.tsx diff --git a/src/components/warning/warning.tsx b/src/components/warning/warning.tsx index 7299c174..9a49ff0f 100644 --- a/src/components/warning/warning.tsx +++ b/src/components/warning/warning.tsx @@ -4,6 +4,7 @@ import * as React from "react"; import { ErrorIcon } from "~/components/icon/icon"; +import { invalidNamingRules } from "~/validators/valid-name"; import { Tooltip } from "@material-ui/core"; interface WarningComponentProps { @@ -25,5 +26,5 @@ interface IllegalNamingWarningProps { export const IllegalNamingWarning = ({ name }: IllegalNamingWarningProps) => ; \ No newline at end of file diff --git a/src/validators/valid-name.tsx b/src/validators/valid-name.tsx new file mode 100644 index 00000000..468811d8 --- /dev/null +++ b/src/validators/valid-name.tsx @@ -0,0 +1,14 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + + +const ERROR_MESSAGE = "Name cannot be '.' or '..' or contain '/' characters"; + +export const invalidNamingRules = [/\//, /^\.{1,2}$/]; + +export const validName = (value: string) => { + return invalidNamingRules.find(aRule => value.match(aRule) !== null) + ? ERROR_MESSAGE + : undefined; +}; diff --git a/src/validators/validators.tsx b/src/validators/validators.tsx index acef9744..13ce4e6a 100644 --- a/src/validators/validators.tsx +++ b/src/validators/validators.tsx @@ -6,13 +6,14 @@ import { require } from './require'; import { maxLength } from './max-length'; import { isRsaKey } from './is-rsa-key'; import { isRemoteHost } from "./is-remote-host"; +import { validName } from "./valid-name"; export const TAG_KEY_VALIDATION = [require, maxLength(255)]; export const TAG_VALUE_VALIDATION = [require, maxLength(255)]; -export const PROJECT_NAME_VALIDATION = [require, maxLength(255)]; +export const PROJECT_NAME_VALIDATION = [require, validName, maxLength(255)]; -export const COLLECTION_NAME_VALIDATION = [require, maxLength(255)]; +export const COLLECTION_NAME_VALIDATION = [require, validName, maxLength(255)]; export const COLLECTION_DESCRIPTION_VALIDATION = [maxLength(255)]; export const COLLECTION_PROJECT_VALIDATION = [require]; -- 2.39.5