summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@theqtcompany.com>2015-11-18 16:58:45 +0100
committeraavit <eirik.aavitsland@theqtcompany.com>2015-11-20 09:18:00 +0000
commit84eae855ee57ab1c37c8a84ad7e7afcd40b919e6 (patch)
tree9bf8cd34f4701e0f3fd4ad19a48537a69d22586e
parent0379fb9186a75394b5cf0a3f5866da3d08b05e18 (diff)
downloadqtsvg-84eae855ee57ab1c37c8a84ad7e7afcd40b919e6.tar.gz
Improve format detection in the image reader pluginv5.6.0-beta1
canRead() would reject a file starting with an xml comment. canRead() by design accepts anything that looks like the start of an xml file, and the comment token "<!--" should be an indicator as good as any of an xml file. Task-number: QTBUG-49496 Change-Id: Id3c17f6b02344fa6a20bc2a839e345e5cebc14c2 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
-rw-r--r--src/plugins/imageformats/svg/qsvgiohandler.cpp4
-rw-r--r--tests/auto/qicon_svg/icons/triangle.svg12
-rw-r--r--tests/auto/qicon_svg/tst_qicon_svg.cpp1
3 files changed, 15 insertions, 2 deletions
diff --git a/src/plugins/imageformats/svg/qsvgiohandler.cpp b/src/plugins/imageformats/svg/qsvgiohandler.cpp
index 8790796..8a9cbb2 100644
--- a/src/plugins/imageformats/svg/qsvgiohandler.cpp
+++ b/src/plugins/imageformats/svg/qsvgiohandler.cpp
@@ -122,7 +122,7 @@ bool QSvgIOHandler::canRead() const
if (buf.startsWith("\x1f\x8b")) {
setFormat("svgz");
return true;
- } else if (buf.contains("<?xml") || buf.contains("<svg")) {
+ } else if (buf.contains("<?xml") || buf.contains("<svg") || buf.contains("<!--")) {
setFormat("svg");
return true;
}
@@ -251,7 +251,7 @@ bool QSvgIOHandler::supportsOption(ImageOption option) const
bool QSvgIOHandler::canRead(QIODevice *device)
{
QByteArray buf = device->peek(8);
- return buf.startsWith("\x1f\x8b") || buf.contains("<?xml") || buf.contains("<svg");
+ return buf.startsWith("\x1f\x8b") || buf.contains("<?xml") || buf.contains("<svg") || buf.contains("<!--");
}
QT_END_NAMESPACE
diff --git a/tests/auto/qicon_svg/icons/triangle.svg b/tests/auto/qicon_svg/icons/triangle.svg
new file mode 100644
index 0000000..e858490
--- /dev/null
+++ b/tests/auto/qicon_svg/icons/triangle.svg
@@ -0,0 +1,12 @@
+<!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In -->
+<svg version="1.1"
+ xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
+ x="0px" y="0px" width="39.2px" height="39.2px" viewBox="0 0 39.2 39.2" style="enable-background:new 0 0 39.2 39.2;"
+ xml:space="preserve">
+<style type="text/css">
+ .st1{fill:#1B1E23;}
+</style>
+<defs>
+</defs>
+<polygon class="st1" points="15.3,11.3 29.2,19.6 15.3,27.9 "/>
+</svg>
diff --git a/tests/auto/qicon_svg/tst_qicon_svg.cpp b/tests/auto/qicon_svg/tst_qicon_svg.cpp
index f5b97e0..893cf99 100644
--- a/tests/auto/qicon_svg/tst_qicon_svg.cpp
+++ b/tests/auto/qicon_svg/tst_qicon_svg.cpp
@@ -60,6 +60,7 @@ void tst_QIcon_Svg::initTestCase()
QFAIL("Can't find images directory!");
if (!QImageReader::supportedImageFormats().contains("svg"))
QFAIL("SVG support is not available");
+ QCOMPARE(QImageReader::imageFormat(prefix + "triangle.svg"), QByteArray("svg"));
}
void tst_QIcon_Svg::svgActualSize()