Skip to content

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
 

‎src/app/qgspythondialog.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ QgsPythonDialog::~QgsPythonDialog()
3232
QgsPythonUtils::uninstallConsoleHooks();
3333
}
3434

35+
QString QgsPythonDialog::escapeHtml(QString text)
36+
{
37+
return text.replace("<","&lt;").replace(">","&gt;");
38+
}
39+
3540
void QgsPythonDialog::on_edtCmdLine_returnPressed()
3641
{
3742
QString command = edtCmdLine->text();
@@ -43,12 +48,10 @@ void QgsPythonDialog::on_edtCmdLine_returnPressed()
4348
{
4449
QgsPythonUtils::evalString("sys.stdout.data", output);
4550
QgsPythonUtils::runString("sys.stdout.data = ''");
46-
QString result = QgsPythonUtils::getResult();
51+
QString result = QgsPythonUtils::getResult();
4752
// escape the result so python objects display properly and
4853
// we can still use html output to get nicely formatted display
49-
result.replace("<","&lt;");
50-
result.replace(">","&gt;");
51-
output += result;
54+
output = escapeHtml(output) + escapeHtml(result);
5255

5356
if (!output.isEmpty())
5457
output += "<br>";
@@ -58,10 +61,10 @@ void QgsPythonDialog::on_edtCmdLine_returnPressed()
5861
QString className, errorText;
5962
QgsPythonUtils::getError(className, errorText);
6063

61-
output = "<font color=\"red\">" + className + ": " + errorText + "</font><br>";
64+
output = "<font color=\"red\">" + escapeHtml(className) + ": " + escapeHtml(errorText) + "</font><br>";
6265
}
6366

64-
QString str = "<b><font color=\"green\">>>></font> " + command.replace("<","&lt;") + "</b><br>" + output;
67+
QString str = "<b><font color=\"green\">>>></font> " + escapeHtml(command) + "</b><br>" + output;
6568
txtHistory->setText(txtHistory->text() + str);
6669
edtCmdLine->setText("");
6770

‎src/app/qgspythondialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class QgsPythonDialog : public QDialog, private Ui::QgsPythonDialog
3030

3131
~QgsPythonDialog();
3232

33+
QString escapeHtml(QString text);
34+
3335
public slots:
3436

3537
void on_edtCmdLine_returnPressed();

0 commit comments

Comments
 (0)
Please sign in to comment.