Skip to content

Commit

Permalink
Validate input of APPLICATION_SERVER_URL.
Browse files Browse the repository at this point in the history
Tries to clean double quotes and output JSON parse error.

Signed-off-by: Camila Ayres <[email protected]>
  • Loading branch information
camilasan authored and mgallien committed Sep 26, 2024
1 parent e467fc8 commit ee351aa
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ Theme::Theme()
_forceOverrideServerUrl = true;
#endif
#ifdef APPLICATION_SERVER_URL
_overrideServerUrl = QString::fromLatin1(APPLICATION_SERVER_URL);
updateMultipleOverrideServers();
setOverrideServerUrl(QString::fromLatin1(APPLICATION_SERVER_URL));
#endif
}

Expand Down Expand Up @@ -438,7 +437,12 @@ bool Theme::forceOverrideServerUrl() const
void Theme::updateMultipleOverrideServers()
{
const auto json = overrideServerUrl().toUtf8();
const auto doc = QJsonDocument::fromJson(json);
QJsonParseError jsonParseError;
const auto doc = QJsonDocument::fromJson(json, &jsonParseError);
if (jsonParseError.error != QJsonParseError::NoError) {
qDebug() << "Parsing array of server urls from APPLICATION_SERVER_URL failed:" << jsonParseError.error << jsonParseError.errorString();
}

_multipleOverrideServers = doc.isArray() && !doc.array().empty();
}

Expand Down Expand Up @@ -967,8 +971,17 @@ bool Theme::darkMode()

void Theme::setOverrideServerUrl(const QString &overrideServerUrl)
{
if (_overrideServerUrl != overrideServerUrl) {
_overrideServerUrl = overrideServerUrl;
auto validOverrideServerUrl = overrideServerUrl;
if (validOverrideServerUrl.startsWith("\"")) {
validOverrideServerUrl.remove(0, 1);
}

if (validOverrideServerUrl.endsWith("\"")) {
validOverrideServerUrl.chop(1);
}

if (_overrideServerUrl != validOverrideServerUrl) {
_overrideServerUrl = validOverrideServerUrl;
updateMultipleOverrideServers();
emit overrideServerUrlChanged();
}
Expand Down

0 comments on commit ee351aa

Please sign in to comment.