Remove comments before using loopProtect on scripts (fixes #218) (#364)

This commit is contained in:
Zach Rispoli 2017-06-05 19:46:19 -07:00 committed by Cassie Tarakajian
parent c596b74b27
commit 3f32ccc89c
2 changed files with 4 additions and 3 deletions

View file

@ -7,6 +7,8 @@ import loopProtect from 'loop-protect';
import { getBlobUrl } from '../actions/files'; import { getBlobUrl } from '../actions/files';
import { resolvePathToFile } from '../../../../server/utils/filePath'; import { resolvePathToFile } from '../../../../server/utils/filePath';
const decomment = require('decomment');
const startTag = '@fs-'; const startTag = '@fs-';
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
const MEDIA_FILE_REGEX = /^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg|json|txt|csv|svg|obj|mp4|ogg|webm|mov|otf|ttf|m4a)('|")$/i; const MEDIA_FILE_REGEX = /^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg|json|txt|csv|svg|obj|mp4|ogg|webm|mov|otf|ttf|m4a)('|")$/i;
@ -56,20 +58,17 @@ function hijackConsoleErrorsScript(offs) {
} }
return [line - l, file]; return [line - l, file];
} }
// catch reference errors, via http://stackoverflow.com/a/12747364/2994108 // catch reference errors, via http://stackoverflow.com/a/12747364/2994108
window.onerror = function (msg, url, lineNumber, columnNo, error) { window.onerror = function (msg, url, lineNumber, columnNo, error) {
var string = msg.toLowerCase(); var string = msg.toLowerCase();
var substring = "script error"; var substring = "script error";
var data = {}; var data = {};
if (string.indexOf(substring) !== -1){ if (string.indexOf(substring) !== -1){
data = 'Script Error: See Browser Console for Detail'; data = 'Script Error: See Browser Console for Detail';
} else { } else {
var fileInfo = getScriptOff(lineNumber); var fileInfo = getScriptOff(lineNumber);
data = msg + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')'; data = msg + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')';
} }
window.parent.postMessage([{ window.parent.postMessage([{
method: 'error', method: 'error',
arguments: data, arguments: data,
@ -281,6 +280,7 @@ class PreviewFrame extends React.Component {
} }
} }
}); });
newContent = decomment(newContent);
newContent = loopProtect(newContent); newContent = loopProtect(newContent);
return newContent; return newContent;
} }

View file

@ -71,6 +71,7 @@
"cookie-parser": "^1.4.1", "cookie-parser": "^1.4.1",
"cors": "^2.8.1", "cors": "^2.8.1",
"csslint": "^0.10.0", "csslint": "^0.10.0",
"decomment": "^0.8.7",
"dotenv": "^2.0.0", "dotenv": "^2.0.0",
"dropzone": "^4.3.0", "dropzone": "^4.3.0",
"escape-string-regexp": "^1.0.5", "escape-string-regexp": "^1.0.5",