From cb6fce016d88622cc361a9f609518db753502e46 Mon Sep 17 00:00:00 2001
From: Chih-Hsuan Yen <yen@chyen.cc>
Date: Wed, 23 Jan 2019 16:41:35 +0800
Subject: [PATCH] Allow <style> without type attribute

According to https://www.w3.org/TR/SVG/styling.html#StyleElement, `type`
can be omitted.

> If the attribute is not specified, then the style sheet language is assumed to be CSS.

Original-Author: Christoph Feck
Fixes: QTBUG-58326
Fixes: QTBUG-69378
Change-Id: Ic3d0e8db99da8c81e5a01c0dda33fb38428e38d5
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
---
 src/svg/qsvghandler.cpp                      |  2 +-
 tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp | 22 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp
index 6d2e279..132c4ec 100644
--- a/src/svg/qsvghandler.cpp
+++ b/src/svg/qsvghandler.cpp
@@ -3203,7 +3203,7 @@ static bool parseStyleNode(QSvgNode *parent,
     Q_UNUSED(handler)
 #else
     const QStringRef type = attributes.value(QLatin1String("type"));
-    if (type.compare(QLatin1String("text/css"), Qt::CaseInsensitive) == 0)
+    if (type.compare(QLatin1String("text/css"), Qt::CaseInsensitive) == 0 || type.isNull())
         handler->setInStyle(true);
 #endif
 
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
index 87d24c7..1bc8b94 100644
--- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
+++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
@@ -74,6 +74,7 @@ private slots:
     void testStopOffsetOpacity();
     void testUseElement();
     void smallFont();
+    void styleSheet();
 
 #ifndef QT_NO_COMPRESS
     void testGzLoading();
@@ -1376,5 +1377,26 @@ void tst_QSvgRenderer::smallFont()
     QVERIFY(images[0] != images[1]);
 }
 
+void tst_QSvgRenderer::styleSheet()
+{
+    static const char *svgs[] = { "<svg><style type=\"text/css\">.cls {fill:#ff0000;}</style><rect class=\"cls\" x = \"10\" y = \"10\" width = \"30\" height = \"30\"/></svg>",
+                                  "<svg><style>.cls {fill:#ff0000;}</style><rect class=\"cls\" x = \"10\" y = \"10\" width = \"30\" height = \"30\"/></svg>",
+    };
+    const int COUNT = sizeof(svgs) / sizeof(svgs[0]);
+    QImage images[COUNT];
+    QPainter p;
+
+    for (int i = 0; i < COUNT; ++i) {
+        QByteArray data(svgs[i]);
+        QSvgRenderer renderer(data);
+        images[i] = QImage(50, 50, QImage::Format_ARGB32_Premultiplied);
+        images[i].fill(-1);
+        p.begin(&images[i]);
+        renderer.render(&p);
+        p.end();
+    }
+    QCOMPARE(images[0], images[1]);
+}
+
 QTEST_MAIN(tst_QSvgRenderer)
 #include "tst_qsvgrenderer.moc"
-- 
2.18.1

