fix: code smells

This commit is contained in:
YiFang Xiao 2023-07-09 18:18:40 +08:00
parent 568efee4c7
commit eb1963b170
2 changed files with 17 additions and 18 deletions

View file

@ -15,10 +15,8 @@ QRegularExpression Ftx::setsRegExp( R"(\[[^\]]+\])", QRegularExpression::CaseIns
QRegularExpression Ftx::regexRegExp( R"(\\[afnrtvdDwWsSbB]|\\x([0-9A-Fa-f]{4})|\\0([0-7]{3}))", QRegularExpression Ftx::regexRegExp( R"(\\[afnrtvdDwWsSbB]|\\x([0-9A-Fa-f]{4})|\\0([0-7]{3}))",
QRegularExpression::CaseInsensitiveOption ); QRegularExpression::CaseInsensitiveOption );
QRegularExpression Ftx::handleRoundBracket( R"([^\w\(\)\p{M}]+)" , QRegularExpression Ftx::handleRoundBracket( R"([^\w\(\)\p{M}]+)", QRegularExpression::UseUnicodePropertiesOption );
QRegularExpression::UseUnicodePropertiesOption ); QRegularExpression Ftx::noRoundBracket( R"([^\w\p{M}]+)", QRegularExpression::UseUnicodePropertiesOption );
QRegularExpression Ftx::noRoundBracket( "[^\\w\\p{M}]+",
QRegularExpression::UseUnicodePropertiesOption );
QRegularExpression Ftx::tokenBoundary( R"([\*\?\+]|\bAnd\b|\bOR\b)", QRegularExpression::CaseInsensitiveOption ); QRegularExpression Ftx::tokenBoundary( R"([\*\?\+]|\bAnd\b|\bOR\b)", QRegularExpression::CaseInsensitiveOption );
QRegularExpression Ftx::token(R"((".*?")|([\w\W\+\-]+))",QRegularExpression::DotMatchesEverythingOption|QRegularExpression::CaseInsensitiveOption); QRegularExpression Ftx::token(R"((".*?")|([\w\W\+\-]+))",QRegularExpression::DotMatchesEverythingOption|QRegularExpression::CaseInsensitiveOption);
@ -47,7 +45,7 @@ QRegularExpression Mdx::stylesRe2(
QRegularExpression::CaseInsensitiveOption ); QRegularExpression::CaseInsensitiveOption );
QRegularExpression Mdx::inlineScriptRe( R"(<\s*script(?:(?=\s)(?:(?![\s"']src\s*=)[^>])+|\s*)>)", QRegularExpression Mdx::inlineScriptRe( R"(<\s*script(?:(?=\s)(?:(?![\s"']src\s*=)[^>])+|\s*)>)",
QRegularExpression::CaseInsensitiveOption ); QRegularExpression::CaseInsensitiveOption );
QRegularExpression Mdx::closeScriptTagRe( "<\\s*/script\\s*>", QRegularExpression::CaseInsensitiveOption ); QRegularExpression Mdx::closeScriptTagRe( R"(<\s*/script\s*>)", QRegularExpression::CaseInsensitiveOption );
QRegularExpression Mdx::srcRe( QRegularExpression Mdx::srcRe(
R"(([\s"'](?:src|srcset)\s*=)\s*(["'])(?!\s*\b(?:(?:bres|https?|ftp)://|(?:data|javascript):))(?:file://)?[\x00-\x1f\x7f]*\.*/?([^">]+)\2)", R"(([\s"'](?:src|srcset)\s*=)\s*(["'])(?!\s*\b(?:(?:bres|https?|ftp)://|(?:data|javascript):))(?:file://)?[\x00-\x1f\x7f]*\.*/?([^">]+)\2)",
QRegularExpression::CaseInsensitiveOption ); QRegularExpression::CaseInsensitiveOption );

View file

@ -30,7 +30,7 @@ void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
codecName = ct.mid( index + 8 ); codecName = ct.mid( index + 8 );
} }
} }
QBuffer * buffer = new QBuffer( requestJob ); auto buffer = new QBuffer( requestJob );
QByteArray replyData = reply->readAll(); QByteArray replyData = reply->readAll();
QString articleString; QString articleString;
@ -61,24 +61,25 @@ 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( "<base\\s+.*?>", QRegularExpression baseTag( R"(<base\s+.*?>)",
QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption ); QRegularExpression::CaseInsensitiveOption
| QRegularExpression::DotMatchesEverythingOption );
QString baseTagHtml = "<base href=\"" + base + "\">";
QString baseTagHtml = QString( R"(<base href="%1">)" ).arg( base );
QString depressionFocus =
R"(<script type="application/javascript"> HTMLElement.prototype.focus=function(){console.log("focus() has been disabled.");}</script>
<script type="text/javascript" src="qrc:///scripts/iframeResizer.contentWindow.min.js">
</script><script type="text/javascript" src="qrc:///scripts/iframe-defer.js"></script>)";
QString depressionFocus ="<script type=\"application/javascript\"> HTMLElement.prototype.focus=function(){console.log(\"focus() has been disabled.\");}</script>"
"<script type=\"text/javascript\" src=\"qrc:///scripts/iframeResizer.contentWindow.min.js\"></script>"
"<script type=\"text/javascript\" src=\"qrc:///scripts/iframe-defer.js\"></script>";
// remove existed base tag // remove existed base tag
articleString.remove( baseTag ) ; articleString.remove( baseTag );
QRegularExpression headTag( "<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, 0 );
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 );
} }