mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-22 22:33:34 -07:00
Apply suggestions from code review
Co-authored-by: Vladimir Golovnev <glassez@yandex.ru>
This commit is contained in:
parent
bfe3b9844a
commit
8c973b89eb
1 changed files with 19 additions and 12 deletions
|
@ -572,22 +572,29 @@ void RSSWidget::convertRelativePathToAbsolute(QString &html, const QString &base
|
||||||
|
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
QRegularExpressionMatch match = iter.next();
|
const QRegularExpressionMatch match = iter.next();
|
||||||
const QString &fullMatch = match.captured(0);
|
|
||||||
const Qstring &prefix = match.captured(1);
|
|
||||||
const QString &scheme = match.captured(4);
|
const QString &scheme = match.captured(4);
|
||||||
const QString &host = match.captured(5);
|
const QString &host = match.captured(5);
|
||||||
|
if (!scheme.isEmpty())
|
||||||
|
{
|
||||||
|
if (host.isEmpty())
|
||||||
|
break; // invalid URL, should never happen
|
||||||
|
|
||||||
|
// already absolute path
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QString relativePath = match.captured(6);
|
QString relativePath = match.captured(6);
|
||||||
const QString &suffix = match.captured(7);
|
|
||||||
if (relativePath.startsWith(u'/'))
|
if (relativePath.startsWith(u'/'))
|
||||||
relativePath = relativePath.mid(1);
|
relativePath = relativePath.mid(1);
|
||||||
if (!scheme.isEmpty() && !host.isEmpty()) // already absolute path
|
|
||||||
continue;
|
if (!host.isEmpty())
|
||||||
else if (!host.isEmpty())
|
|
||||||
normalizedBasePath = u"http:" + host;
|
normalizedBasePath = u"http:" + host;
|
||||||
else if (!scheme.isEmpty())
|
|
||||||
break; // invalid url, should never happen
|
const QString &fullMatch = match.captured(0);
|
||||||
QString absolutePath = normalizedBasePath + relativePath;
|
const QString &prefix = match.captured(1);
|
||||||
|
const QString &suffix = match.captured(7);
|
||||||
|
const QString absolutePath = normalizedBasePath + relativePath;
|
||||||
|
|
||||||
html.replace(fullMatch, prefix + absolutePath + suffix);
|
html.replace(fullMatch, prefix + absolutePath + suffix);
|
||||||
}
|
}
|
||||||
|
@ -646,8 +653,8 @@ void RSSWidget::renderArticle(const RSS::Article *article) const
|
||||||
}
|
}
|
||||||
// Supplement relative path to absolute path
|
// Supplement relative path to absolute path
|
||||||
|
|
||||||
QUrl url {article->link()};
|
const QUrl url {article->link()};
|
||||||
QString basePath = url.scheme() + u"://" + url.host();
|
const QString basePath = url.scheme() + u"://" + url.host();
|
||||||
convertRelativePathToAbsolute(html, basePath);
|
convertRelativePathToAbsolute(html, basePath);
|
||||||
html += u"</div>";
|
html += u"</div>";
|
||||||
m_ui->textBrowser->setHtml(html);
|
m_ui->textBrowser->setHtml(html);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue