diff --git a/client/package-lock.json b/client/package-lock.json index 3a962d4a50..96d8b614de 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -5189,9 +5189,9 @@ } }, "entities": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz", - "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=" + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==" }, "envify": { "version": "4.1.0", diff --git a/client/package.json b/client/package.json index 84e088e433..be3607848c 100644 --- a/client/package.json +++ b/client/package.json @@ -19,6 +19,7 @@ "browser-cookies": "^1.2.0", "chai": "^4.2.0", "date-fns": "^1.29.0", + "entities": "^1.1.2", "enzyme": "^3.6.0", "enzyme-adapter-react-16": "^1.5.0", "fetchr": "^0.5.37", diff --git a/client/src/templates/Challenges/classic/Show.js b/client/src/templates/Challenges/classic/Show.js index aff229f80e..fa4bebc3c6 100644 --- a/client/src/templates/Challenges/classic/Show.js +++ b/client/src/templates/Challenges/classic/Show.js @@ -39,8 +39,6 @@ import { import './classic.css'; import '../components/test-frame.css'; -import decodeHTMLEntities from '../../../../utils/decodeHTMLEntities'; - const mapStateToProps = createStructuredSelector({ files: challengeFilesSelector, tests: challengeTestsSelector, @@ -237,7 +235,7 @@ class ShowClassic extends Component { * Your test output will go here. */ `} - output={decodeHTMLEntities(output)} + output={output} /> ); } diff --git a/client/src/templates/Challenges/components/Output.js b/client/src/templates/Challenges/components/Output.js index df46ff37a4..9f60af997b 100644 --- a/client/src/templates/Challenges/components/Output.js +++ b/client/src/templates/Challenges/components/Output.js @@ -1,6 +1,7 @@ import React, { Fragment, Component } from 'react'; import PropTypes from 'prop-types'; import MonacoEditor from 'react-monaco-editor'; +import { decodeHTML } from 'entities'; const propTypes = { defaultOutput: PropTypes.string, @@ -51,7 +52,7 @@ class Output extends Component { editorDidMount={::this.editorDidMount} height={height} options={options} - value={output ? output : defaultOutput} + value={decodeHTML(output ? output : defaultOutput)} /> ); diff --git a/client/src/templates/Challenges/redux/execute-challenge-saga.js b/client/src/templates/Challenges/redux/execute-challenge-saga.js index 585a4e3462..1992e18cc7 100644 --- a/client/src/templates/Challenges/redux/execute-challenge-saga.js +++ b/client/src/templates/Challenges/redux/execute-challenge-saga.js @@ -148,7 +148,9 @@ function* executeTests(testRunner) { throw err; } } catch (err) { - newTest.message = text.replace(/(.*?)<\/code>/g, '$1'); + newTest.message = text + .replace(/(.*?)<\/code>/g, '$1') + .replace(//g, ''); if (err === 'timeout') { newTest.err = 'Test timed out'; newTest.message = `${newTest.message} (${newTest.err})`; diff --git a/client/utils/decodeHTMLEntities.js b/client/utils/decodeHTMLEntities.js deleted file mode 100644 index 5d95cee352..0000000000 --- a/client/utils/decodeHTMLEntities.js +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Converts HTML entity codes in a string to the characters they represent. - * - * Example: - * `decodeHTMLEntities('Beets & carrots');` - * will return "Beets & carrots". - * - * The regex makes sure we only replace the HTML entities in the string. - * For example, the regex would match "<" as well as ":". - * The decoding works by setting the innerHTML of a dummy element and then - * retrieving the innerText. Per the spec, innerText is a property that - * represents the "rendered" text content of an element. - * - * See: - * https://developer.mozilla.org/en-US/docs/Web/API/Node/innerText - * https://developer.mozilla.org/en-US/docs/Glossary/Entity - * - */ -const decodeHTMLEntities = str => { - const el = document.createElement('div'); - return str.replace(/&[#0-9a-z]+;/gi, enc => { - el.innerHTML = enc; - return el.innerText; - }); -}; - -export default decodeHTMLEntities;