mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-22 22:33:34 -07:00
Correct terms and move into anonymous namespace
This commit is contained in:
parent
3d4efedab8
commit
c3dcba3b4a
1 changed files with 42 additions and 36 deletions
|
@ -53,9 +53,10 @@
|
||||||
#include "automatedrssdownloader.h"
|
#include "automatedrssdownloader.h"
|
||||||
#include "feedlistwidget.h"
|
#include "feedlistwidget.h"
|
||||||
#include "ui_rsswidget.h"
|
#include "ui_rsswidget.h"
|
||||||
|
namespace
|
||||||
|
{
|
||||||
void convertRelativeUrlToAbsolute(QString &html, const QString &baseUrl);
|
void convertRelativeUrlToAbsolute(QString &html, const QString &baseUrl);
|
||||||
|
}
|
||||||
RSSWidget::RSSWidget(IGUIApplication *app, QWidget *parent)
|
RSSWidget::RSSWidget(IGUIApplication *app, QWidget *parent)
|
||||||
: GUIApplicationComponent(app, parent)
|
: GUIApplicationComponent(app, parent)
|
||||||
, m_ui {new Ui::RSSWidget}
|
, m_ui {new Ui::RSSWidget}
|
||||||
|
@ -613,48 +614,53 @@ void RSSWidget::renderArticle(const RSS::Article *article) const
|
||||||
html += u"<pre>" + description + u"</pre>";
|
html += u"<pre>" + description + u"</pre>";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supplement relative path to absolute path
|
// Supplement relative URLs to absolute ones
|
||||||
const QUrl url {article->link()};
|
const QUrl url {article->link()};
|
||||||
const QString baseUrl = url.toString(QUrl::RemovePath | QUrl::RemoveQuery);
|
const QString baseUrl = url.toString(QUrl::RemovePath | QUrl::RemoveQuery);
|
||||||
convertRelativeUrlToAbsolute(html, baseUrl);
|
convertRelativeUrlToAbsolute(html, baseUrl);
|
||||||
html += u"</div>";
|
html += u"</div>";
|
||||||
m_ui->textBrowser->setHtml(html);
|
m_ui->textBrowser->setHtml(html);
|
||||||
}
|
}
|
||||||
|
namespace
|
||||||
void convertRelativeUrlToAbsolute(QString &html, const QString &baseUrl)
|
|
||||||
{
|
{
|
||||||
const QRegularExpression rx {uR"(((<a\s+[^>]*?href|<img\s+[^>]*?src)\s*=\s*["'])((https?|ftp):)?(\/\/[^\/]*)?(\/?[^\/"].*?)(["']))"_s
|
void convertRelativeUrlToAbsolute(QString &html, const QString &baseUrl)
|
||||||
, QRegularExpression::CaseInsensitiveOption};
|
|
||||||
|
|
||||||
QString normalizedBaseUrl = baseUrl.endsWith(u'/') ? baseUrl : baseUrl + u'/';
|
|
||||||
QRegularExpressionMatchIterator iter = rx.globalMatch(html);
|
|
||||||
|
|
||||||
while (iter.hasNext())
|
|
||||||
{
|
{
|
||||||
const QRegularExpressionMatch match = iter.next();
|
const QRegularExpression rx {uR"(((<a\s+[^>]*?href|<img\s+[^>]*?src)\s*=\s*["'])((https?|ftp):)?(\/\/[^\/]*)?(\/?[^\/"].*?)(["']))"_s
|
||||||
const QString scheme = match.captured(4);
|
, QRegularExpression::CaseInsensitiveOption};
|
||||||
const QString host = match.captured(5);
|
|
||||||
if (!scheme.isEmpty())
|
QString normalizedBaseUrl = baseUrl.endsWith(u'/') ? baseUrl : baseUrl + u'/';
|
||||||
|
const QUrl url {normalizedBaseUrl};
|
||||||
|
const QString defaultScheme = url.scheme();
|
||||||
|
QRegularExpressionMatchIterator iter = rx.globalMatch(html);
|
||||||
|
|
||||||
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
if (host.isEmpty())
|
const QRegularExpressionMatch match = iter.next();
|
||||||
break; // invalid URL, should never happen
|
const QString scheme = match.captured(4);
|
||||||
|
const QString host = match.captured(5);
|
||||||
// already absolute path
|
if (!scheme.isEmpty())
|
||||||
continue;
|
{
|
||||||
|
if (host.isEmpty())
|
||||||
|
break; // invalid URL, should never happen
|
||||||
|
|
||||||
|
// already absolute URL
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString relativePath = match.captured(6);
|
||||||
|
if (relativePath.startsWith(u'/'))
|
||||||
|
relativePath = relativePath.mid(1);
|
||||||
|
|
||||||
|
if (!host.isEmpty())
|
||||||
|
{
|
||||||
|
normalizedBaseUrl = defaultScheme + u":" + host;
|
||||||
|
}
|
||||||
|
const QString fullMatch = match.captured(0);
|
||||||
|
const QString prefix = match.captured(1);
|
||||||
|
const QString suffix = match.captured(7);
|
||||||
|
const QString absoluteUrl = normalizedBaseUrl + relativePath;
|
||||||
|
|
||||||
|
html.replace(fullMatch, (prefix + absoluteUrl + suffix));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString relativePath = match.captured(6);
|
|
||||||
if (relativePath.startsWith(u'/'))
|
|
||||||
relativePath = relativePath.mid(1);
|
|
||||||
|
|
||||||
if (!host.isEmpty())
|
|
||||||
normalizedBaseUrl = u"http:" + host;
|
|
||||||
|
|
||||||
const QString fullMatch = match.captured(0);
|
|
||||||
const QString prefix = match.captured(1);
|
|
||||||
const QString suffix = match.captured(7);
|
|
||||||
const QString absolutePath = normalizedBaseUrl + relativePath;
|
|
||||||
|
|
||||||
html.replace(fullMatch, (prefix + absolutePath + suffix));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue