16041: Adjust name validation behavior depending on ForwardSlashNameSubstitution
[arvados-workbench2.git] / src / validators / valid-name.tsx
index 468811d831a3ec0214ceb025750bf7645791f45b..da96712398e278f6a45de0cd57a6395a7691ad7b 100644 (file)
@@ -2,13 +2,19 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+export const disallowDotName = /^\.{1,2}$/;
+export const disallowSlash = /\//;
 
 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)
+    return [disallowDotName, disallowSlash].find(aRule => value.match(aRule) !== null)
         ? ERROR_MESSAGE
         : undefined;
 };
+
+export const validNameAllowSlash = (value: string) => {
+    return [disallowDotName].find(aRule => value.match(aRule) !== null)
+        ? "Name cannot be '.' or '..'"
+        : undefined;
+};