prevent users from adding extension to folder name
This commit is contained in:
parent
1dd723cb9f
commit
d4914983a4
2 changed files with 7 additions and 3 deletions
|
@ -67,13 +67,15 @@ export class FileNode extends React.Component {
|
|||
validateFileName() {
|
||||
const oldFileExtension = this.originalFileName.match(/\.[0-9a-z]+$/i);
|
||||
const newFileExtension = this.props.name.match(/\.[0-9a-z]+$/i);
|
||||
const hasPeriod = this.props.name.match(/\.+/);
|
||||
const newFileName = this.props.name;
|
||||
const hasNoExtension = oldFileExtension && !newFileExtension;
|
||||
const notSameExtension = oldFileExtension && newFileExtension &&
|
||||
oldFileExtension[0].toLowerCase() !== newFileExtension[0].toLowerCase();
|
||||
const hasExtensionIfFolder = this.props.fileType === 'folder' && hasPeriod;
|
||||
const notSameExtension = oldFileExtension && newFileExtension
|
||||
&& oldFileExtension[0].toLowerCase() !== newFileExtension[0].toLowerCase();
|
||||
const hasEmptyFilename = newFileName === '';
|
||||
const hasOnlyExtension = newFileExtension && newFileName === newFileExtension[0];
|
||||
if (hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension) {
|
||||
if (hasEmptyFilename || hasNoExtension || notSameExtension || hasOnlyExtension || hasExtensionIfFolder) {
|
||||
this.props.updateFileName(this.props.id, this.originalFileName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ function validate(formProps) {
|
|||
errors.name = 'Please enter a name';
|
||||
} else if (formProps.name.trim().length === 0) {
|
||||
errors.name = 'Folder name cannot contain only spaces';
|
||||
} else if (formProps.name.match(/\.+/i)) {
|
||||
errors.name = 'Folder name cannot contain an extension';
|
||||
}
|
||||
|
||||
return errors;
|
||||
|
|
Loading…
Reference in a new issue