fix: website dictionary base tag (#1038)

* fix: website dictionary base tag

* [autofix.ci] apply automated fixes

* fix: request header origin

---------

Co-authored-by: YiFang Xiao <yifang.xiao@noreply.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
xiaoyifang 2023-08-03 21:29:36 +08:00 committed by GitHub
parent bea926bdd9
commit ac8e79358c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View file

@ -61,10 +61,15 @@ void IframeSchemeHandler::requestStarted( QWebEngineUrlRequestJob * requestJob )
QString root = reply->url().scheme() + "://" + reply->url().host(); QString root = reply->url().scheme() + "://" + reply->url().host();
QString base = root + reply->url().path(); QString base = root + reply->url().path();
QRegularExpression baseTag( R"(<base\s+.*?>)", QRegularExpression baseTag( R"EOF(<base\s+href=["'](.*?)["'].*?>)EOF",
QRegularExpression::CaseInsensitiveOption QRegularExpression::CaseInsensitiveOption
| QRegularExpression::DotMatchesEverythingOption ); | QRegularExpression::DotMatchesEverythingOption );
if ( const auto match = baseTag.match( articleString ); match.hasMatch() ) {
base = reply->url().resolved( match.captured( 1 ) ).url();
}
QString baseTagHtml = QString( R"(<base href="%1">)" ).arg( base ); QString baseTagHtml = QString( R"(<base href="%1">)" ).arg( base );
QString depressionFocus = QString depressionFocus =
@ -72,14 +77,14 @@ void IframeSchemeHandler::requestStarted( QWebEngineUrlRequestJob * requestJob )
<script type="text/javascript" src="qrc:///scripts/iframeResizer.contentWindow.min.js"> <script type="text/javascript" src="qrc:///scripts/iframeResizer.contentWindow.min.js">
</script><script type="text/javascript" src="qrc:///scripts/iframe-defer.js"></script>)"; </script><script type="text/javascript" src="qrc:///scripts/iframe-defer.js"></script>)";
// remove existed base tag
articleString.remove( baseTag ); articleString.remove( baseTag );
articleString.replace( "window.location", "window.location;_window_location" ); articleString.replace( "window.location", "window.location;_window_location" );
QRegularExpression headTag( R"(<head\b.*?>)", QRegularExpression headTag( R"(<head\b.*?>)",
QRegularExpression::CaseInsensitiveOption QRegularExpression::CaseInsensitiveOption
| QRegularExpression::DotMatchesEverythingOption ); | QRegularExpression::DotMatchesEverythingOption );
auto match = headTag.match( articleString, 0 ); auto match = headTag.match( articleString );
if ( match.hasMatch() ) { if ( match.hasMatch() ) {
articleString.insert( match.capturedEnd(), baseTagHtml ); articleString.insert( match.capturedEnd(), baseTagHtml );
articleString.insert( match.capturedEnd(), depressionFocus ); articleString.insert( match.capturedEnd(), depressionFocus );

View file

@ -9,8 +9,7 @@ WebUrlRequestInterceptor::WebUrlRequestInterceptor( QObject * p ):
} }
void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo & info ) void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo & info )
{ {
info.setHttpHeader( "origin", info.requestUrl().url().toUtf8() );
info.setHttpHeader( "origin", "*" );
info.setHttpHeader( "referer", info.requestUrl().url().toUtf8() ); info.setHttpHeader( "referer", info.requestUrl().url().toUtf8() );
if ( GlobalBroadcaster::instance()->getPreference()->disallowContentFromOtherSites if ( GlobalBroadcaster::instance()->getPreference()->disallowContentFromOtherSites
&& Utils::isExternalLink( info.requestUrl() ) ) { && Utils::isExternalLink( info.requestUrl() ) ) {