ETag: Allow parsing of weak tags #3946
authorChristian Kamm <mail@ckamm.de>
Thu, 15 Oct 2015 12:57:06 +0000 (14:57 +0200)
committerChristian Kamm <mail@ckamm.de>
Thu, 15 Oct 2015 12:57:34 +0000 (14:57 +0200)
src/libsync/owncloudpropagator_p.h
test/testowncloudpropagator.h

index aa1aa1cb959853401e0b43b6e426c176535c51e1..3b188a2eff77ed5ab598d2ad4e8b3cd71f5ca477 100644 (file)
@@ -25,7 +25,14 @@ inline QByteArray parseEtag(const char *header) {
     if (!header)
         return QByteArray();
     QByteArray arr = header;
-    arr.replace("-gzip", ""); // https://github.comowncloud/client/issues/1195
+
+    // Weak E-Tags can appear when gzip compression is on, see #3946
+    if (arr.startsWith("W/"))
+        arr = arr.mid(2);
+
+    // https://github.com/owncloud/client/issues/1195
+    arr.replace("-gzip", "");
+
     if(arr.length() >= 2 && arr.startsWith('"') && arr.endsWith('"')) {
         arr = arr.mid(1, arr.length() - 2);
     }
index 24cdcdcd63082d9ac06bc4c0e95b2b6b99e64bc2..2347135d8d70dabfde8ace00e7b47670d4ff945c 100644 (file)
@@ -11,6 +11,7 @@
 #include <QDebug>
 
 #include "propagatedownload.h"
+#include "owncloudpropagator_p.h"
 
 using namespace OCC;
 namespace OCC {
@@ -64,6 +65,20 @@ private slots:
             QVERIFY( tmpFileName.length() <= 254);
         }
     }
+
+    void testParseEtag()
+    {
+        typedef QPair<const char*, const char*> Test;
+        QList<Test> tests;
+        tests.append(Test("\"abcd\"", "abcd"));
+        tests.append(Test("\"\"", ""));
+        tests.append(Test("\"fii\"-gzip", "fii"));
+        tests.append(Test("W/\"foo\"", "foo"));
+
+        foreach (const auto& test, tests) {
+            QCOMPARE(parseEtag(test.first), test.second);
+        }
+    }
 };
 
 #endif