Skip to content

Commit

Permalink
Merge pull request #5289 from nextcloud/bugfix/static-qregularexpress…
Browse files Browse the repository at this point in the history
…ions

Declare all QRegularExpressions statically
  • Loading branch information
claucambra authored Dec 20, 2022
2 parents 8313d79 + ce57d3b commit 77bb54c
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/gui/creds/oauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void OAuth::start()
QByteArray peek = socket->peek(qMin(socket->bytesAvailable(), 4000LL)); //The code should always be within the first 4K
if (peek.indexOf('\n') < 0)
return; // wait until we find a \n
const QRegularExpression rx("^GET /\\?code=([a-zA-Z0-9]+)[& ]"); // Match a /?code=... URL
static const QRegularExpression rx("^GET /\\?code=([a-zA-Z0-9]+)[& ]"); // Match a /?code=... URL
const auto rxMatch = rx.match(peek);
if (!rxMatch.hasMatch()) {
httpReplyAndClose(socket, "404 Not Found", "<html><head><title>404 Not Found</title></head><body><center><h1>404 Not Found</h1></center></body></html>");
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editlocallyjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ bool EditLocallyJob::isTokenValid(const QString &token)

// Token is an alphanumeric string 128 chars long.
// Ensure that is what we received and what we are sending to the server.
const QRegularExpression tokenRegex("^[a-zA-Z0-9]{128}$");
static const QRegularExpression tokenRegex("^[a-zA-Z0-9]{128}$");
const auto regexMatch = tokenRegex.match(token);

return regexMatch.hasMatch();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/notificationconfirmjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool NotificationConfirmJob::finished()
const QString replyStr = reply()->readAll();

if (replyStr.contains("<?xml version=\"1.0\"?>")) {
const QRegularExpression rex("<statuscode>(\\d+)</statuscode>");
static const QRegularExpression rex("<statuscode>(\\d+)</statuscode>");
const auto rexMatch = rex.match(replyStr);
if (rexMatch.hasMatch()) {
// this is a error message coming back from ocs.
Expand Down
2 changes: 1 addition & 1 deletion src/gui/syncrunfilelog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void SyncRunFileLog::logItem(const SyncFileItem &item)
}
QString ts = QString::fromLatin1(item._responseTimeStamp);
if (ts.length() > 6) {
const QRegularExpression rx(R"((\d\d:\d\d:\d\d))");
static const QRegularExpression rx(R"((\d\d:\d\d:\d\d))");
const auto rxMatch = rx.match(ts);
if (rxMatch.hasMatch()) {
ts = rxMatch.captured(0);
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void Logger::enterNextLogFile()
// Expire old log files and deal with conflicts
QStringList files = dir.entryList(QStringList("*owncloud.log.*"), QDir::Files, QDir::Name) +
dir.entryList(QStringList("*nextcloud.log.*"), QDir::Files, QDir::Name);
const QRegularExpression rx(QRegularExpression::anchoredPattern(R"(.*(next|own)cloud\.log\.(\d+).*)"));
static const QRegularExpression rx(QRegularExpression::anchoredPattern(R"(.*(next|own)cloud\.log\.(\d+).*)"));
int maxNumber = -1;
foreach (const QString &s, files) {
if (_logExpire > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/networkjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ bool JsonApiJob::finished()

QString jsonStr = QString::fromUtf8(reply()->readAll());
if (jsonStr.contains("<?xml version=\"1.0\"?>")) {
const QRegularExpression rex("<statuscode>(\\d+)</statuscode>");
static const QRegularExpression rex("<statuscode>(\\d+)</statuscode>");
const auto rexMatch = rex.match(jsonStr);
if (rexMatch.hasMatch()) {
// this is a error message coming back from ocs.
Expand All @@ -850,7 +850,7 @@ bool JsonApiJob::finished()
qCWarning(lcJsonApiJob) << "Nothing changed so nothing to retrieve - status code: " << httpStatusCode;
statusCode = httpStatusCode;
} else {
const QRegularExpression rex(R"("statuscode":(\d+))");
static const QRegularExpression rex(R"("statuscode":(\d+))");
// example: "{"ocs":{"meta":{"status":"ok","statuscode":100,"message":null},"data":{"version":{"major":8,"minor":"... (504)
const auto rxMatch = rex.match(jsonStr);
if (rxMatch.hasMatch()) {
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void GETFileJob::slotMetaDataChanged()
qint64 start = 0;
QByteArray ranges = reply()->rawHeader("Content-Range");
if (!ranges.isEmpty()) {
const QRegularExpression rx("bytes (\\d+)-");
static const QRegularExpression rx("bytes (\\d+)-");
const auto rxMatch = rx.match(ranges);
if (rxMatch.hasMatch()) {
start = rxMatch.captured(1).toLongLong();
Expand Down
3 changes: 2 additions & 1 deletion src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@ void Theme::replaceLinkColorStringBackgroundAware(QString &linkString)

void Theme::replaceLinkColorString(QString &linkString, const QColor &newColor)
{
linkString.replace(QRegularExpression("(<a href|<a style='color:#([a-zA-Z0-9]{6});' href)"), QString::fromLatin1("<a style='color:%1;' href").arg(newColor.name()));
static const QRegularExpression linkRegularExpression("(<a href|<a style='color:#([a-zA-Z0-9]{6});' href)");
linkString.replace(linkRegularExpression, QString::fromLatin1("<a style='color:%1;' href").arg(newColor.name()));
}

QIcon Theme::createColorAwareIcon(const QString &name, const QPalette &palette)
Expand Down

0 comments on commit 77bb54c

Please sign in to comment.