Wiki: Fix urls in "srcset" attribute (issue #1096)

This commit is contained in:
Abs62 2019-03-04 19:36:58 +03:00
parent e7e37cbbeb
commit 9bae6d2201

View file

@ -541,6 +541,43 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
// Add url scheme to other urls like "//xxx" // Add url scheme to other urls like "//xxx"
articleString.replace( " href=\"//", " href=\"" + wikiUrl.scheme() + "://" ); articleString.replace( " href=\"//", " href=\"" + wikiUrl.scheme() + "://" );
// Fix urls in "srcset" attribute
pos = 0;
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
QRegularExpression regSrcset( " srcset\\s*=\\s*\"/[^\"]+\"" );
it = regSrcset.globalMatch( articleString );
while( it.hasNext() )
{
QRegularExpressionMatch match = it.next();
articleNewString += articleString.midRef( pos, match.capturedStart() - pos );
pos = match.capturedEnd();
QString srcset = match.captured();
#else
QRegExp regSrcset( " srcset\\s*=\\s*\"/([^\"]+)\"" );
for( ; ; )
{
pos = regSrcset.indexIn( articleString, pos );
if( pos < 0 )
break;
QString srcset = regSrcset.cap();
#endif
QString newSrcset = srcset.replace( "//", wikiUrl.scheme() + "://" );
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
articleNewString += newSrcset;
}
if( pos )
{
articleNewString += articleString.midRef( pos );
articleString = articleNewString;
articleNewString.clear();
}
#else
articleString.replace( pos, regSrcset.cap().size(), newSrcset );
pos += newSrcset.size();
}
#endif
QByteArray articleBody = articleString.toUtf8(); QByteArray articleBody = articleString.toUtf8();
articleBody.prepend( dictPtr->isToLanguageRTL() ? "<div class=\"mwiki\" dir=\"rtl\">" : articleBody.prepend( dictPtr->isToLanguageRTL() ? "<div class=\"mwiki\" dir=\"rtl\">" :