Show all url schemas in entry view (#1768)

* Show all url schemas in entry view
* Fix UUID being built improperly with invalid user input
This commit is contained in:
Jonathan White 2018-07-14 17:08:04 -04:00 committed by GitHub
parent 3727d37101
commit add4ba21fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 24 deletions

View File

@ -287,8 +287,7 @@ QString Entry::webUrl() const
QString Entry::displayUrl() const
{
QString url = maskPasswordPlaceholders(m_attributes->value(EntryAttributes::URLKey));
url = resolveMultiplePlaceholders(url);
return resolveUrl(url);
return resolveMultiplePlaceholders(url);
}
QString Entry::username() const

View File

@ -88,13 +88,19 @@ bool Uuid::operator!=(const Uuid& other) const
Uuid Uuid::fromBase64(const QString& str)
{
QByteArray data = QByteArray::fromBase64(str.toLatin1());
return Uuid(data);
if (data.size() == Uuid::Length) {
return Uuid(data);
}
return {};
}
Uuid Uuid::fromHex(const QString& str)
{
QByteArray data = QByteArray::fromHex(str.toLatin1());
return Uuid(data);
if (data.size() == Uuid::Length) {
return Uuid(data);
}
return {};
}
uint qHash(const Uuid& key)

View File

@ -633,25 +633,22 @@ void DatabaseWidget::openUrl()
void DatabaseWidget::openUrlForEntry(Entry* entry)
{
QString urlString = entry->resolveMultiplePlaceholders(entry->url());
if (urlString.isEmpty()) {
return;
}
if (urlString.startsWith("cmd://")) {
QString cmdString = entry->resolveMultiplePlaceholders(entry->url());
if (cmdString.startsWith("cmd://")) {
// check if decision to execute command was stored
if (entry->attributes()->hasKey(EntryAttributes::RememberCmdExecAttr)) {
if (entry->attributes()->value(EntryAttributes::RememberCmdExecAttr) == "1") {
QProcess::startDetached(urlString.mid(6));
QProcess::startDetached(cmdString.mid(6));
}
return;
}
// otherwise ask user
if (urlString.length() > 6) {
QString cmdTruncated = urlString.mid(6);
if (cmdTruncated.length() > 400)
if (cmdString.length() > 6) {
QString cmdTruncated = cmdString.mid(6);
if (cmdTruncated.length() > 400) {
cmdTruncated = cmdTruncated.left(400) + " […]";
}
QMessageBox msgbox(QMessageBox::Icon::Question,
tr("Execute command?"),
tr("Do you really want to execute the following command?<br><br>%1<br>")
@ -672,7 +669,7 @@ void DatabaseWidget::openUrlForEntry(Entry* entry)
int result = msgbox.exec();
if (result == QMessageBox::Yes) {
QProcess::startDetached(urlString.mid(6));
QProcess::startDetached(cmdString.mid(6));
}
if (remember) {
@ -680,10 +677,11 @@ void DatabaseWidget::openUrlForEntry(Entry* entry)
result == QMessageBox::Yes ? "1" : "0");
}
}
}
else {
QUrl url = QUrl::fromUserInput(urlString);
QDesktopServices::openUrl(url);
} else {
QString urlString = entry->webUrl();
if (!urlString.isEmpty()) {
QDesktopServices::openUrl(urlString);
}
}
}

View File

@ -174,17 +174,15 @@ void DetailsWidget::updateEntryGeneralTab()
m_ui->entryPasswordLabel->setToolTip({});
}
m_ui->entryUrlLabel->setRawText(m_currentEntry->displayUrl());
const QString url = m_currentEntry->webUrl();
if (!url.isEmpty()) {
// URL is well formed and can be opened in a browser
// create a new display url that masks password placeholders
// the actual link will use the password
m_ui->entryUrlLabel->setRawText(m_currentEntry->displayUrl());
m_ui->entryUrlLabel->setUrl(url);
m_ui->entryUrlLabel->setCursor(Qt::PointingHandCursor);
} else {
// Fallback to the raw url string
m_ui->entryUrlLabel->setRawText(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->url()));
m_ui->entryUrlLabel->setUrl({});
m_ui->entryUrlLabel->setCursor(Qt::ArrowCursor);
}
const TimeInfo entryTime = m_currentEntry->timeInfo();

View File

@ -203,6 +203,9 @@
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>
</property>
</widget>
</item>
<item row="0" column="2">