X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/af2033d68980358c141ad61c9f82a450d30f4acb..HEAD:/src/validators/valid-name.tsx

diff --git a/src/validators/valid-name.tsx b/src/validators/valid-name.tsx
index da967123..89bb3f96 100644
--- a/src/validators/valid-name.tsx
+++ b/src/validators/valid-name.tsx
@@ -4,12 +4,12 @@
 
 export const disallowDotName = /^\.{1,2}$/;
 export const disallowSlash = /\//;
-
-const ERROR_MESSAGE = "Name cannot be '.' or '..' or contain '/' characters";
+export const disallowLeadingWhitespaces = /^\s+/;
+export const disallowTrailingWhitespaces = /\s+$/;
 
 export const validName = (value: string) => {
     return [disallowDotName, disallowSlash].find(aRule => value.match(aRule) !== null)
-        ? ERROR_MESSAGE
+        ? "Name cannot be '.' or '..' or contain '/' characters"
         : undefined;
 };
 
@@ -18,3 +18,20 @@ export const validNameAllowSlash = (value: string) => {
         ? "Name cannot be '.' or '..'"
         : undefined;
 };
+
+export const validFileName = (value: string) => {
+    return [
+        disallowLeadingWhitespaces,
+        disallowTrailingWhitespaces
+    ].find(aRule => value.match(aRule) !== null)
+        ? `Leading/trailing whitespaces not allowed on '${value}'`
+        : undefined;
+};
+
+export const validFilePath = (filePath: string) => {
+    const errors = filePath.split('/').map(pathPart => {
+        if (pathPart === "") { return "Empty dir name not allowed"; }
+        return validNameAllowSlash(pathPart) || validFileName(pathPart);
+    });
+    return errors.filter(e => e !== undefined)[0];
+};
\ No newline at end of file
