Skip to content

Commit

Permalink
Fixup budget proposal URLs that are lacking scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
CaveSpectre11 committed Jul 15, 2019
1 parent 918852c commit 8768556
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/masternode-budget.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,19 @@ class CBudgetProposal

void CleanAndRemove(bool fSignatureCheck);

// If URL doesn't have a scheme, add one
std::string GetFixedupURL(std::string scheme="http")
{
std::string ret=strURL;
std::string delim ("://");
if (strURL.find(delim) == std::string::npos)
{
// URL is missing scheme; add one
ret = scheme+"://"+strURL;
}
return ret;
}

uint256 GetHash() const
{
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
Expand Down
10 changes: 5 additions & 5 deletions src/qt/proposalframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void ProposalFrame::refresh()

QLabel* strProposalURL = new QLabel();
strProposalURL->setObjectName(QStringLiteral("strProposalURL"));
QString strURL = QString::fromStdString(proposal->GetURL());
QString strURL = QString::fromStdString(proposal->GetFixedupURL());
QString strClick = tr("Open proposal page in browser");
strProposalURL->setText("<a href=\"" + strURL + "\">" + strClick + "</a>");
strProposalURL->setTextFormat(Qt::RichText);
Expand Down Expand Up @@ -182,7 +182,7 @@ void ProposalFrame::proposalLink_clicked(const QString &link)
{
QMessageBox Msgbox;
QString strMsgBox = tr("A proposal URL can be used for phishing, scams and computer viruses. Open this link only if you trust the following URL.\n");
strMsgBox += QString::fromStdString(proposal->GetURL());
strMsgBox += QString::fromStdString(proposal->GetFixedupURL());
Msgbox.setText(strMsgBox);
Msgbox.setStandardButtons(QMessageBox::Cancel);
QAbstractButton *openButton = Msgbox.addButton(tr("Open link"), QMessageBox::ApplyRole);
Expand All @@ -192,10 +192,10 @@ void ProposalFrame::proposalLink_clicked(const QString &link)
Msgbox.exec();

if (Msgbox.clickedButton() == openButton) {
QDesktopServices::openUrl(QUrl(QString::fromStdString(proposal->GetURL())));
QDesktopServices::openUrl(QUrl(QString::fromStdString(proposal->GetFixedupURL())));
}
if (Msgbox.clickedButton() == copyButton) {
QGuiApplication::clipboard()->setText(QString::fromStdString(proposal->GetURL()));
QGuiApplication::clipboard()->setText(QString::fromStdString(proposal->GetFixedupURL()));
}
governancePage->lockUpdating(false);
}
Expand Down Expand Up @@ -246,7 +246,7 @@ void ProposalFrame::voteButton_clicked(int nVote)
questionString += tr("using all your masternodes?");
questionString += "<br /><br />";
questionString += tr("Proposal Hash:") + " " + QString::fromStdString(proposal->GetHash().ToString()) + "<br />";
questionString += tr("Proposal URL:") + " " + QString::fromStdString(proposal->GetURL());
questionString += tr("Proposal URL:") + " " + QString::fromStdString(proposal->GetFixedupURL());
governancePage->lockUpdating(true);
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm Vote"),
questionString,
Expand Down
7 changes: 7 additions & 0 deletions src/rpc/budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ UniValue preparebudget(const UniValue& params, bool fHelp)
std::string strURL = SanitizeString(params[1].get_str());
if (strURL.size() > 64)
throw runtime_error("Invalid url, limit of 64 characters.");
if ((strURL.find("://") == std::string::npos) ||
((strURL.front() != 'h') && (strURL.front() != 'H')))
throw std::runtime_error("Invalid url format, add scheme (e.g. https://).");


int nPaymentCount = params[2].get_int();
if (nPaymentCount < 1)
Expand Down Expand Up @@ -180,6 +184,9 @@ UniValue submitbudget(const UniValue& params, bool fHelp)
std::string strURL = SanitizeString(params[1].get_str());
if (strURL.size() > 64)
throw runtime_error("Invalid url, limit of 64 characters.");
if ((strURL.find("://") == std::string::npos) ||
((strURL.front() != 'h') && (strURL.front() != 'H')))
throw std::runtime_error("Invalid url format, add scheme (e.g. https://).");

int nPaymentCount = params[2].get_int();
if (nPaymentCount < 1)
Expand Down

0 comments on commit 8768556

Please sign in to comment.