1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 export const disallowDotName = /^\.{1,2}$/;
6 export const disallowSlash = /\//;
7 export const disallowLeadingWhitespaces = /^\s+/;
8 export const disallowTrailingWhitespaces = /\s+$/;
10 export const validName = (value: string) => {
11 return [disallowDotName, disallowSlash].find(aRule => value.match(aRule) !== null)
12 ? "Name cannot be '.' or '..' or contain '/' characters"
16 export const validNameAllowSlash = (value: string) => {
17 return [disallowDotName].find(aRule => value.match(aRule) !== null)
18 ? "Name cannot be '.' or '..'"
22 export const validFileName = (value: string) => {
24 disallowLeadingWhitespaces,
25 disallowTrailingWhitespaces
26 ].find(aRule => value.match(aRule) !== null)
27 ? `Leading/trailing whitespaces not allowed on '${value}'`
31 export const validFilePath = (filePath: string) => {
32 const errors = filePath.split('/').map(pathPart => {
33 if (pathPart === "") { return "Empty dir name not allowed"; }
34 return validNameAllowSlash(pathPart) || validFileName(pathPart);
36 return errors.filter(e => e !== undefined)[0];