diff --git a/src/lib/src/functions.cpp b/src/lib/src/functions.cpp index 4f6c62d76..72d19db64 100644 --- a/src/lib/src/functions.cpp +++ b/src/lib/src/functions.cpp @@ -464,7 +464,12 @@ QString getExtension(const QString &url) { const int lastDot = url.lastIndexOf('.'); if (lastDot != -1) { - return url.mid(lastDot + 1); + const int doubleDot = url.midRef(lastDot + 1).indexOf(':'); + if (doubleDot != -1) { + return url.mid(lastDot + 1, doubleDot); + } else { + return url.mid(lastDot + 1); + } } return QString(); } @@ -490,7 +495,8 @@ QUrl setExtension(QUrl url, const QString &extension) const int lastSlash = path.lastIndexOf('/'); const int lastDot = path.midRef(lastSlash + 1).lastIndexOf('.'); if (lastDot != -1) { - url.setPath(path.left(lastDot + lastSlash + 1) + "." + extension); + const int doubleDot = path.midRef(lastDot + 1).indexOf(':'); + url.setPath(path.left(lastDot + lastSlash + 1) + "." + extension + (doubleDot != -1 ? path.mid(lastDot + doubleDot + 1) : "")); } return url; diff --git a/src/tests/src/functions-test.cpp b/src/tests/src/functions-test.cpp index 26d840b1d..40e828514 100644 --- a/src/tests/src/functions-test.cpp +++ b/src/tests/src/functions-test.cpp @@ -192,7 +192,8 @@ TEST_CASE("Functions") REQUIRE(getExtension(QUrl("http://test.com/some.dir/file")) == QString("")); REQUIRE(getExtension(QUrl("http://test.com/file.jpg")) == QString("jpg")); REQUIRE(getExtension(QUrl("http://test.com/file.jpg?toto=1")) == QString("jpg")); - REQUIRE(getExtension(QUrl("http://test.com/file.jpg?toto=1")) == QString("jpg")); + REQUIRE(getExtension(QUrl("http://test.com/file.jpg:large")) == QString("jpg")); + REQUIRE(getExtension(QUrl("http://test.com/index.php?image=file.jpg")) == QString("jpg")); } SECTION("SetExtension") { @@ -200,6 +201,7 @@ TEST_CASE("Functions") REQUIRE(setExtension(QUrl("http://test.com/file"), "png") == QUrl("http://test.com/file")); REQUIRE(setExtension(QUrl("http://test.com/file.jpg"), "png") == QUrl("http://test.com/file.png")); REQUIRE(setExtension(QUrl("http://test.com/file.jpg?toto=1"), "png") == QUrl("http://test.com/file.png?toto=1")); + REQUIRE(setExtension(QUrl("http://test.com/file.jpg:large"), "png") == QUrl("http://test.com/file.png:large")); } SECTION("Levenshtein")