From cc456200a2e618fe3e865ecd8b364cb2af230936 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Wed, 17 Jul 2019 12:30:26 -0400 Subject: [PATCH] prevent users from adding extension to folder name --- client/modules/IDE/components/FileNode.jsx | 8 +++++--- client/modules/IDE/components/NewFolderModal.jsx | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/modules/IDE/components/FileNode.jsx b/client/modules/IDE/components/FileNode.jsx index a9c4f0a7..1b28bd4e 100644 --- a/client/modules/IDE/components/FileNode.jsx +++ b/client/modules/IDE/components/FileNode.jsx @@ -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); } } diff --git a/client/modules/IDE/components/NewFolderModal.jsx b/client/modules/IDE/components/NewFolderModal.jsx index 4d1e714c..60483ce8 100644 --- a/client/modules/IDE/components/NewFolderModal.jsx +++ b/client/modules/IDE/components/NewFolderModal.jsx @@ -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;