]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Validate input of APPLICATION_SERVER_URL.
authorCamila Ayres <hello@camilasan.com>
Wed, 25 Sep 2024 16:25:00 +0000 (18:25 +0200)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 26 Sep 2024 12:55:29 +0000 (14:55 +0200)
Tries to clean double quotes and output JSON parse error.

Signed-off-by: Camila Ayres <hello@camilasan.com>
src/libsync/theme.cpp

index 407db59bab6721fadf9add37b9369703d5b342bc..85efef02be0f442e01837f881650ac8aed0eeb1e 100644 (file)
@@ -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
 }
 
@@ -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();
 }
 
@@ -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();
     }