Skip to content

Commit 6829d5d

Browse files
committed
refactor(asyncimageresponse): use QMimeDatabase for SVG check
Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
1 parent f233f29 commit 6829d5d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/gui/tray/asyncimageresponse.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "asyncimageresponse.h"
77

88
#include <QIcon>
9+
#include <QMimeDatabase>
910
#include <QPainter>
1011
#include <QSvgRenderer>
1112

@@ -116,11 +117,10 @@ void AsyncImageResponse::processNetworkReply(QNetworkReply *reply)
116117
return;
117118
}
118119

119-
// check whether the reply might be an SVG by looking at the content type and the first 512 bytes of the response for `<svg`.
120120
// Some graphics programs export SVGs that begin with `<?xml version="1.0" [...]` and/or include some comments after that (e.g.
121121
// `<!-- Generator: ...`), so we can't rely on just the response to start with `<svg`.
122-
if (const auto contentTypeHeader = reply->header(QNetworkRequest::ContentTypeHeader);
123-
!(contentTypeHeader.toString().startsWith("image/svg"_ba) || imageData.first(qMin(imageData.size(), 512)).contains("<svg"_ba))) {
122+
if (const auto mimetype = QMimeDatabase().mimeTypeForData(imageData);
123+
!(mimetype.isValid() && mimetype.inherits("image/svg+xml"_L1))) {
124124
// Not an SVG: let's let QImage deal with the response.
125125
setImageAndEmitFinished(QImage::fromData(imageData).scaled(_requestedImageSize));
126126
return;

0 commit comments

Comments
 (0)