From 02f4cb23b488e5aaacabd4cd9618cd8fd61716d6 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Thu, 26 Sep 2019 16:17:22 -0400 Subject: [PATCH] fixes #1162, fixes #1118 --- client/modules/IDE/components/NewFileModal.jsx | 5 +++-- server/utils/fileUtils.js | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/client/modules/IDE/components/NewFileModal.jsx b/client/modules/IDE/components/NewFileModal.jsx index aeed9598..433c3daa 100644 --- a/client/modules/IDE/components/NewFileModal.jsx +++ b/client/modules/IDE/components/NewFileModal.jsx @@ -5,6 +5,7 @@ import classNames from 'classnames'; import InlineSVG from 'react-inlinesvg'; import NewFileForm from './NewFileForm'; import FileUploader from './FileUploader'; +import { CREATE_FILE_REGEX } from '../../../../server/utils/fileUtils'; const exitUrl = require('../../../images/exit.svg'); @@ -71,8 +72,8 @@ function validate(formProps) { if (!formProps.name) { errors.name = 'Please enter a name'; - } else if (!formProps.name.match(/(.+\.js$|.+\.css$|.+\.json$|.+\.txt$|.+\.csv$|.+\.tsv$)/i)) { - errors.name = 'File must be of type JavaScript, CSS, JSON, TXT, CSV, or TSV.'; + } else if (!formProps.name.match(CREATE_FILE_REGEX)) { + errors.name = 'Invalid file type. Valid extensions are .js, .css, .json, .txt, .csv, .tsv, .frag, and .vert.'; } return errors; diff --git a/server/utils/fileUtils.js b/server/utils/fileUtils.js index 0e6a7e58..c63cff9f 100644 --- a/server/utils/fileUtils.js +++ b/server/utils/fileUtils.js @@ -3,7 +3,7 @@ export const fileExtensionsArray = ['gif', 'jpg', 'jpeg', 'png', 'bmp', 'wav', 'flac', 'ogg', 'oga', 'mp4', 'm4p', 'mp3', 'm4a', 'aiff', 'aif', 'm4v', 'aac', 'webm', 'mpg', 'mp2', 'mpeg', 'mpe', 'mpv', 'js', 'jsx', 'html', 'htm', 'css', 'json', 'csv', 'obj', 'svg', - 'otf', 'ttf', 'txt', 'mov', 'vert', 'frag']; + 'otf', 'ttf', 'txt', 'mov', 'vert', 'frag', 'bin']; export const mimeTypes = `image/*,audio/*,text/javascript,text/html,text/css, application/json,application/x-font-ttf,application/x-font-truetype,text/plain, @@ -22,6 +22,8 @@ export const STRING_REGEX = /(['"])((\\\1|.)*?)\1/gm; // these are files that have to be linked to with a blob url export const PLAINTEXT_FILE_REGEX = /.+\.(json|txt|csv|vert|frag|tsv)$/i; // these are files that users would want to edit as text (maybe svg should be here?) -export const TEXT_FILE_REGEX = /.+\.(json|txt|csv|vert|frag|js|css|html|htm|jsx)$/i; +export const TEXT_FILE_REGEX = /.+\.(json|txt|csv|tsv|vert|frag|js|css|html|htm|jsx)$/i; export const NOT_EXTERNAL_LINK_REGEX = /^(?!(http:\/\/|https:\/\/))/; export const EXTERNAL_LINK_REGEX = /^(http:\/\/|https:\/\/)/; + +export const CREATE_FILE_REGEX = /.+\.(json|txt|csv|tsv|js|css|frag|vert)$/i;