diff --git a/src/libsync/owncloudpropagator_p.h b/src/libsync/owncloudpropagator_p.h index aa1aa1cb959..3b188a2eff7 100644 --- a/src/libsync/owncloudpropagator_p.h +++ b/src/libsync/owncloudpropagator_p.h @@ -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); } diff --git a/test/testowncloudpropagator.h b/test/testowncloudpropagator.h index 24cdcdcd630..2347135d8d7 100644 --- a/test/testowncloudpropagator.h +++ b/test/testowncloudpropagator.h @@ -11,6 +11,7 @@ #include #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 Test; + QList 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