Skip to content

Commit 12662d1

Browse files
committed
Escape html entities in console
Fix #4020
1 parent 6011ea7 commit 12662d1

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/app/qmlutils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,8 @@ void QmlUtils::deleteTextWrapper(QObject *w)
165165
w->deleteLater();
166166
}
167167
}
168+
169+
QString QmlUtils::escapeHtmlEntities(const QString &t)
170+
{
171+
return t.toHtmlEscaped();
172+
}

src/app/qmlutils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ class QmlUtils : public QObject
2222
Q_INVOKABLE void addNewValueToDynamicChart(QtCharts::QXYSeries* series, double value);
2323
Q_INVOKABLE QObject* wrapLargeText(const QByteArray &text);
2424
Q_INVOKABLE void deleteTextWrapper(QObject* w);
25+
Q_INVOKABLE QString escapeHtmlEntities(const QString& t);
2526
};

src/qml/console/QConsole.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ Rectangle {
3838
function addOutput(text, type) {
3939

4040
if (type == "error") {
41-
textArea.append("<span style='color: red'>" + text + '</span>')
41+
textArea.append("<span style='color: red'>" + qmlUtils.escapeHtmlEntities(text) + '</span>')
4242
} else {
43-
textArea.append("<pre style='color: white'>" + text + '</pre>')
43+
textArea.append("<pre style='color: white'>" + qmlUtils.escapeHtmlEntities(text) + '</pre>')
4444
}
4545

4646
if (type == "complete" || type == "error") {

0 commit comments

Comments
 (0)