16041: Adjust name validation behavior depending on ForwardSlashNameSubstitution
[arvados-workbench2.git] / src / validators / valid-name.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 export const disallowDotName = /^\.{1,2}$/;
6 export const disallowSlash = /\//;
7
8 const ERROR_MESSAGE = "Name cannot be '.' or '..' or contain '/' characters";
9
10 export const validName = (value: string) => {
11     return [disallowDotName, disallowSlash].find(aRule => value.match(aRule) !== null)
12         ? ERROR_MESSAGE
13         : undefined;
14 };
15
16 export const validNameAllowSlash = (value: string) => {
17     return [disallowDotName].find(aRule => value.match(aRule) !== null)
18         ? "Name cannot be '.' or '..'"
19         : undefined;
20 };