From 81ec52ea92ae612553baeefef87ee6c5dedf20f8 Mon Sep 17 00:00:00 2001 From: 864907600cc Date: Wed, 2 Aug 2017 09:21:07 +0800 Subject: [PATCH] Fix parsing HTML/JSX tags to real elements (#2796) * Fix parsing HTML/JSX tags to real elements * Use `html-entities` to escape instead of pure `replace()` * Remove unnecessary HTML entity replacing --- packages/react-dev-utils/ansiHTML.js | 4 +++- packages/react-dev-utils/webpackHotDevClient.js | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-dev-utils/ansiHTML.js b/packages/react-dev-utils/ansiHTML.js index 9f53cea67..90bf70374 100644 --- a/packages/react-dev-utils/ansiHTML.js +++ b/packages/react-dev-utils/ansiHTML.js @@ -10,6 +10,8 @@ 'use strict'; var Anser = require('anser'); +var Entities = require('html-entities').AllHtmlEntities; +var entities = new Entities(); // Color scheme inspired by https://chriskempson.github.io/base16/css/base16-github.css // var base00 = 'ffffff'; // Default Background @@ -61,7 +63,7 @@ var anserMap = { }; function ansiHTML(txt) { - var arr = new Anser().ansiToJson(txt, { + var arr = new Anser().ansiToJson(entities.encode(txt), { use_classes: true, }); diff --git a/packages/react-dev-utils/webpackHotDevClient.js b/packages/react-dev-utils/webpackHotDevClient.js index 78002b28e..f2f206a5c 100644 --- a/packages/react-dev-utils/webpackHotDevClient.js +++ b/packages/react-dev-utils/webpackHotDevClient.js @@ -22,9 +22,7 @@ var SockJS = require('sockjs-client'); var stripAnsi = require('strip-ansi'); var url = require('url'); var formatWebpackMessages = require('./formatWebpackMessages'); -var Entities = require('html-entities').AllHtmlEntities; var ansiHTML = require('./ansiHTML'); -var entities = new Entities(); function createOverlayIframe(onIframeLoad) { var iframe = document.createElement('iframe'); @@ -138,7 +136,7 @@ function showErrorOverlay(message) { 'margin-bottom: 0.5em; overflow-x: auto; white-space: pre-wrap; ' + 'border-radius: 0.25rem; background-color: rgba(206, 17, 38, 0.05)">' + '' + - ansiHTML(entities.encode(message)) + + ansiHTML(message) + '' + '