From 3f32ccc89cc4c5f2279aa94da79018e6fe17afa2 Mon Sep 17 00:00:00 2001 From: Zach Rispoli Date: Mon, 5 Jun 2017 19:46:19 -0700 Subject: [PATCH] Remove comments before using loopProtect on scripts (fixes #218) (#364) --- client/modules/IDE/components/PreviewFrame.jsx | 6 +++--- package.json | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client/modules/IDE/components/PreviewFrame.jsx b/client/modules/IDE/components/PreviewFrame.jsx index 12fc014e..31bcd90d 100644 --- a/client/modules/IDE/components/PreviewFrame.jsx +++ b/client/modules/IDE/components/PreviewFrame.jsx @@ -7,6 +7,8 @@ import loopProtect from 'loop-protect'; import { getBlobUrl } from '../actions/files'; import { resolvePathToFile } from '../../../../server/utils/filePath'; +const decomment = require('decomment'); + const startTag = '@fs-'; // 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; @@ -56,20 +58,17 @@ function hijackConsoleErrorsScript(offs) { } return [line - l, file]; } - // catch reference errors, via http://stackoverflow.com/a/12747364/2994108 window.onerror = function (msg, url, lineNumber, columnNo, error) { var string = msg.toLowerCase(); var substring = "script error"; var data = {}; - if (string.indexOf(substring) !== -1){ data = 'Script Error: See Browser Console for Detail'; } else { var fileInfo = getScriptOff(lineNumber); data = msg + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')'; } - window.parent.postMessage([{ method: 'error', arguments: data, @@ -281,6 +280,7 @@ class PreviewFrame extends React.Component { } } }); + newContent = decomment(newContent); newContent = loopProtect(newContent); return newContent; } diff --git a/package.json b/package.json index 376ebfad..16e0f414 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "cookie-parser": "^1.4.1", "cors": "^2.8.1", "csslint": "^0.10.0", + "decomment": "^0.8.7", "dotenv": "^2.0.0", "dropzone": "^4.3.0", "escape-string-regexp": "^1.0.5",