From 1de8c02cf2dc2c7483ca65957631c844828cfa6d Mon Sep 17 00:00:00 2001 From: catarak Date: Thu, 25 Aug 2016 12:39:36 -0400 Subject: [PATCH] fix a few regexes for preview frame --- client/modules/IDE/actions/uploader.js | 7 ++++--- client/modules/IDE/components/FileUploader.js | 8 ++++++-- client/modules/IDE/components/PreviewFrame.js | 2 +- client/modules/IDE/reducers/files.js | 6 +++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/client/modules/IDE/actions/uploader.js b/client/modules/IDE/actions/uploader.js index ad5e9c51..44173a59 100644 --- a/client/modules/IDE/actions/uploader.js +++ b/client/modules/IDE/actions/uploader.js @@ -1,5 +1,6 @@ import axios from 'axios'; import { createFile } from './files'; +const textFileRegex = /text\//; const s3Bucket = `http://${process.env.S3_BUCKET}.s3.amazonaws.com/`; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; @@ -34,7 +35,7 @@ export function dropzoneAcceptCallback(file, done) { // check mime type // if text, local interceptor console.log(file.type); - if (file.type.match(/text\//)) { + if (file.type.match(textFileRegex)) { localIntercept(file).then(result => { file.content = result; // eslint-disable-line done(); @@ -74,7 +75,7 @@ export function dropzoneAcceptCallback(file, done) { export function dropzoneSendingCallback(file, xhr, formData) { return () => { - if (!file.type.match(/text\//)) { + if (!file.type.match(textFileRegex)) { Object.keys(file.postData).forEach(key => { formData.append(key, file.postData[key]); }); @@ -87,7 +88,7 @@ export function dropzoneSendingCallback(file, xhr, formData) { export function dropzoneCompleteCallback(file) { return (dispatch, getState) => { // eslint-disable-line - if (!file.type.match(/text\//)) { + if (!file.type.match(textFileRegex)) { let inputHidden = ' { - if (jsFileString.match(/^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg)('|")$/)) { + if (jsFileString.match(/^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg|json)('|")$/i)) { const filePath = jsFileString.substr(1, jsFileString.length - 2); let fileName = filePath; if (fileName.match(/^\.\//)) { diff --git a/client/modules/IDE/reducers/files.js b/client/modules/IDE/reducers/files.js index ff1a5a16..0f19f511 100644 --- a/client/modules/IDE/reducers/files.js +++ b/client/modules/IDE/reducers/files.js @@ -131,9 +131,9 @@ export const setSelectedFile = (state, id) => }); export const getFile = (state, id) => state.filter(file => file.id === id)[0]; -export const getHTMLFile = (state) => state.filter(file => file.name.match(/.*\.html$/))[0]; -export const getJSFiles = (state) => state.filter(file => file.name.match(/.*\.js$/)); -export const getCSSFiles = (state) => state.filter(file => file.name.match(/.*\.css$/)); +export const getHTMLFile = (state) => state.filter(file => file.name.match(/.*\.html$/i))[0]; +export const getJSFiles = (state) => state.filter(file => file.name.match(/.*\.js$/i)); +export const getCSSFiles = (state) => state.filter(file => file.name.match(/.*\.css$/i)); export const getLinkedFiles = (state) => state.filter(file => file.url); export default files;