From 60dd7ca7037f74bc4b018168afff3a351b7781a4 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Sun, 9 Jun 2019 01:58:10 +0200 Subject: [PATCH] fix: Change test output formatting from code to html (#35857) --- client/package.json | 1 + .../templates/Challenges/components/Output.js | 59 ++++--------------- .../Challenges/components/output.css | 12 ++++ .../redux/execute-challenge-saga.js | 4 +- 4 files changed, 26 insertions(+), 50 deletions(-) create mode 100644 client/src/templates/Challenges/components/output.css diff --git a/client/package.json b/client/package.json index 22b4811b2b..76bad90463 100644 --- a/client/package.json +++ b/client/package.json @@ -63,6 +63,7 @@ "redux-saga": "^0.16.0", "reselect": "^3.0.1", "rxjs": "^6.4.0", + "sanitize-html": "^1.20.0", "sass.js": "^0.10.13", "store": "^2.0.12", "validator": "^10.11.0", diff --git a/client/src/templates/Challenges/components/Output.js b/client/src/templates/Challenges/components/Output.js index 9f60af997b..8600a4c21f 100644 --- a/client/src/templates/Challenges/components/Output.js +++ b/client/src/templates/Challenges/components/Output.js @@ -1,60 +1,25 @@ -import React, { Fragment, Component } from 'react'; +import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import MonacoEditor from 'react-monaco-editor'; -import { decodeHTML } from 'entities'; +import sanitizeHtml from 'sanitize-html'; + +import './output.css'; const propTypes = { defaultOutput: PropTypes.string, - dimensions: PropTypes.object, - height: PropTypes.number, output: PropTypes.string }; -const options = { - lineNumbers: false, - minimap: { - enabled: false - }, - readOnly: true, - wordWrap: 'on', - scrollBeyondLastLine: false, - scrollbar: { - horizontal: 'hidden', - vertical: 'visible', - verticalHasArrows: true - } -}; - class Output extends Component { - constructor() { - super(); - - this._editor = null; - } - - editorDidMount(editor) { - this._editor = editor; - } - - componentDidUpdate(prevProps) { - if (this.props.dimensions !== prevProps.dimensions && this._editor) { - this._editor.layout(); - } - } - render() { - const { output, defaultOutput, height } = this.props; + const { output, defaultOutput } = this.props; + const message = sanitizeHtml(output ? output : defaultOutput, { + allowedTags: ['b', 'i', 'em', 'strong', 'code', 'wbr'] + }); return ( - - - - +
     );
   }
 }
diff --git a/client/src/templates/Challenges/components/output.css b/client/src/templates/Challenges/components/output.css
new file mode 100644
index 0000000000..161e2c206b
--- /dev/null
+++ b/client/src/templates/Challenges/components/output.css
@@ -0,0 +1,12 @@
+.output-text {
+  white-space: pre-line;
+  word-break: normal;
+  padding-top: 0;
+  height: 100%;
+  width: 100%;
+  overflow-y: auto;
+}
+
+pre.output-text code {
+  color: #c7254e;
+}
diff --git a/client/src/templates/Challenges/redux/execute-challenge-saga.js b/client/src/templates/Challenges/redux/execute-challenge-saga.js
index 246c256904..bd0e4241f9 100644
--- a/client/src/templates/Challenges/redux/execute-challenge-saga.js
+++ b/client/src/templates/Challenges/redux/execute-challenge-saga.js
@@ -98,9 +98,7 @@ function* executeTests(testRunner, tests, testTimeout = 5000) {
         throw err;
       }
     } catch (err) {
-      newTest.message = text
-        .replace(/(.*?)<\/code>/g, '$1')
-        .replace(//g, '');
+      newTest.message = text;
       if (err === 'timeout') {
         newTest.err = 'Test timed out';
         newTest.message = `${newTest.message} (${newTest.err})`;