Skip to content

Commit

Permalink
TextNode characters are re-escaped in htmlWidgets now. Fixes #1533
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Mar 23, 2023
1 parent c2171a0 commit a4d6e1f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/web/utils/htmlWidget.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import {WidgetType, Decoration, ViewPlugin} from "@codemirror/view";
import {escapeControlChars} from "./editorUtils.mjs";
import {htmlCopyOverride} from "./copyOverride.mjs";
import Utils from "../../core/Utils.mjs";


/**
Expand Down Expand Up @@ -64,7 +65,11 @@ class HTMLWidget extends WidgetType {
* @param {DOMNode} textNode
*/
replaceControlChars(textNode) {
const val = escapeControlChars(textNode.nodeValue, true, this.view.state.lineBreak);
// .nodeValue unencodes HTML encoding such as &lt; to "<"
// We must remember to escape any potential HTML in TextNodes as we do not
// want to render it.
const textValue = Utils.escapeHtml(textNode.nodeValue);
const val = escapeControlChars(textValue, true, this.view.state.lineBreak);
if (val.length !== textNode.nodeValue.length) {
const node = document.createElement("span");
node.innerHTML = val;
Expand Down

0 comments on commit a4d6e1f

Please sign in to comment.