Skip to content

Commit

Permalink
ETag: Allow parsing of weak tags #3946
Browse files Browse the repository at this point in the history
  • Loading branch information
ckamm committed Oct 15, 2015
1 parent df2418d commit abd6303
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libsync/owncloudpropagator_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ inline QByteArray parseEtag(const char *header) {
if (!header)
return QByteArray();
QByteArray arr = header;
arr.replace("-gzip", ""); // https://github.saobby.my.eu.orgowncloud/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);
}
Expand Down
15 changes: 15 additions & 0 deletions test/testowncloudpropagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QDebug>

#include "propagatedownload.h"
#include "owncloudpropagator_p.h"

using namespace OCC;
namespace OCC {
Expand Down Expand Up @@ -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

0 comments on commit abd6303

Please sign in to comment.