Skip to content

Commit 4c329d4

Browse files
committed
Merge #16826: Do additional character escaping for wallet names and address labels
ad52f05 Escape ampersands (&) in wallet names in Open Wallet menu (Andrew Chow) 2c530ea HTML escape address labels in more dialogs and notifications (Andrew Chow) 1770a97 HTML escape the wallet name in more dialogs and notifications (Andrew Chow) Pull request description: Fixes some places where wallet names and address labels which contain valid html or other interpreted characters are displayed incorrectly. In the send coins dialog, if the wallet name or the address label contains valid html, then the html would be shown rather than the literal string for the wallet name or label. This PR fixes that so the true name or label is shown. The Open Wallet menu would incorrectly show wallet names with ampersands (`&`). For some reason, Qt removes the first ampersand in a string. So by replacing the first ampersand with 2 ampersands, the correct number of ampersands will be shown. Fixes the HTML escaping issues in #16820 ACKs for top commit: laanwj: Untested ACK, thanks for adding proper escaping, ad52f05 fanquake: ACK ad52f05 Tree-SHA512: 264bef28a8061c7f43cc30c3e04b361c614ea78b9915e8763c44553c8967131b066db500977fa6130de1f8874b9bba59e630486c58e1e3c5c165555105a6c254
2 parents 08bb4c3 + ad52f05 commit 4c329d4

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/qt/bitcoingui.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ void BitcoinGUI::createActions()
375375
for (const std::pair<const std::string, bool>& i : m_wallet_controller->listWalletDir()) {
376376
const std::string& path = i.first;
377377
QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path);
378+
// Menu items remove single &. Single & are shown when && is in the string, but only the first occurrence. So replace only the first & with &&
379+
name.replace(name.indexOf(QChar('&')), 1, QString("&&"));
378380
QAction* action = m_open_wallet_menu->addAction(name);
379381

380382
if (i.second) {

src/qt/sendcoinsdialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void SendCoinsDialog::on_sendButton_clicked()
283283
// generate amount string with wallet name in case of multiwallet
284284
QString amount = BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount);
285285
if (model->isMultiwallet()) {
286-
amount.append(tr(" from wallet '%1'").arg(model->getWalletName()));
286+
amount.append(tr(" from wallet '%1'").arg(GUIUtil::HtmlEscape(model->getWalletName())));
287287
}
288288

289289
// generate address string
@@ -297,7 +297,7 @@ void SendCoinsDialog::on_sendButton_clicked()
297297
{
298298
if(rcp.label.length() > 0) // label with address
299299
{
300-
recipientElement.append(tr("%1 to '%2'").arg(amount, rcp.label));
300+
recipientElement.append(tr("%1 to '%2'").arg(amount, GUIUtil::HtmlEscape(rcp.label)));
301301
recipientElement.append(QString(" (%1)").arg(address));
302302
}
303303
else // just address

src/qt/walletcontroller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void WalletController::closeWallet(WalletModel* wallet_model, QWidget* parent)
7575
{
7676
QMessageBox box(parent);
7777
box.setWindowTitle(tr("Close wallet"));
78-
box.setText(tr("Are you sure you wish to close wallet <i>%1</i>?").arg(wallet_model->getDisplayName()));
78+
box.setText(tr("Are you sure you wish to close wallet <i>%1</i>?").arg(GUIUtil::HtmlEscape(wallet_model->getDisplayName())));
7979
box.setInformativeText(tr("Closing the wallet for too long can result in having to resync the entire chain if pruning is enabled."));
8080
box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel);
8181
box.setDefaultButton(QMessageBox::Yes);

src/qt/walletview.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int
170170
QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
171171
QModelIndex index = ttm->index(start, 0, parent);
172172
QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();
173-
QString label = ttm->data(index, TransactionTableModel::LabelRole).toString();
173+
QString label = GUIUtil::HtmlEscape(ttm->data(index, TransactionTableModel::LabelRole).toString());
174174

175-
Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label, walletModel->getWalletName());
175+
Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label, GUIUtil::HtmlEscape(walletModel->getWalletName()));
176176
}
177177

178178
void WalletView::gotoOverviewPage()

0 commit comments

Comments
 (0)