summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/svg/qsvghandler.cpp28
-rw-r--r--src/svg/qsvgtinydocument.cpp12
-rw-r--r--tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp39
3 files changed, 61 insertions, 18 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp
index dd31965..599ed56 100644
--- a/src/svg/qsvghandler.cpp
+++ b/src/svg/qsvghandler.cpp
@@ -774,21 +774,31 @@ static QVector<qreal> parsePercentageList(const QChar *&str)
static QString idFromUrl(const QString &url)
{
+ // The form is url(<IRI>), where IRI can be
+ // just an ID on #<id> form.
QString::const_iterator itr = url.constBegin();
QString::const_iterator end = url.constEnd();
+ QString id;
while (itr != end && (*itr).isSpace())
++itr;
if (itr != end && (*itr) == QLatin1Char('('))
++itr;
+ else
+ return QString();
while (itr != end && (*itr).isSpace())
++itr;
- if (itr != end && (*itr) == QLatin1Char('#'))
+ if (itr != end && (*itr) == QLatin1Char('#')) {
+ id += *itr;
++itr;
- QString id;
+ } else {
+ return QString();
+ }
while (itr != end && (*itr) != QLatin1Char(')')) {
id += *itr;
++itr;
}
+ if (itr == end || (*itr) != QLatin1Char(')'))
+ return QString();
return id;
}
@@ -1596,7 +1606,7 @@ static bool parsePathDataFast(const QStringRef &dataStr, QPainterPath &path)
const QChar *end = str + dataStr.size();
while (str != end) {
- while (str->isSpace())
+ while (str->isSpace() && (str + 1) != end)
++str;
QChar pathElem = *str;
++str;
@@ -3709,14 +3719,20 @@ bool QSvgHandler::startElement(const QString &localName,
}
break;
default:
+ const QByteArray msg = QByteArrayLiteral("Could not add child element to parent element because the types are incorrect.");
+ qCWarning(lcSvgHandler, "%s", prefixMessage(msg, xml).constData());
+ delete node;
+ node = 0;
break;
}
}
- parseCoreNode(node, attributes);
+ if (node) {
+ parseCoreNode(node, attributes);
#ifndef QT_NO_CSSPARSER
- cssStyleLookup(node, this, m_selector);
+ cssStyleLookup(node, this, m_selector);
#endif
- parseStyle(node, attributes, this);
+ parseStyle(node, attributes, this);
+ }
} else if (FactoryMethod method = findGraphicsFactory(localName)) {
//rendering element
Q_ASSERT(!m_nodes.isEmpty());
diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp
index 15351bd..da464cc 100644
--- a/src/svg/qsvgtinydocument.cpp
+++ b/src/svg/qsvgtinydocument.cpp
@@ -187,6 +187,7 @@ QSvgTinyDocument * QSvgTinyDocument::load(const QString &fileName)
} else {
qCWarning(lcSvgHandler, "Cannot read file '%s', because: %s (line %d)",
qPrintable(fileName), qPrintable(handler.errorString()), handler.lineNumber());
+ delete handler.document();
}
return doc;
}
@@ -207,6 +208,8 @@ QSvgTinyDocument * QSvgTinyDocument::load(const QByteArray &contents)
if (handler.ok()) {
doc = handler.document();
doc->m_animationDuration = handler.animationDuration();
+ } else {
+ delete handler.document();
}
return doc;
}
@@ -219,6 +222,8 @@ QSvgTinyDocument * QSvgTinyDocument::load(QXmlStreamReader *contents)
if (handler.ok()) {
doc = handler.document();
doc->m_animationDuration = handler.animationDuration();
+ } else {
+ delete handler.document();
}
return doc;
}
@@ -358,7 +363,10 @@ QSvgNode *QSvgTinyDocument::namedNode(const QString &id) const
void QSvgTinyDocument::addNamedStyle(const QString &id, QSvgFillStyleProperty *style)
{
- m_namedStyles.insert(id, style);
+ if (!m_namedStyles.contains(id))
+ m_namedStyles.insert(id, style);
+ else
+ qCWarning(lcSvgHandler) << "Duplicate unique style id:" << id;
}
QSvgFillStyleProperty *QSvgTinyDocument::namedStyle(const QString &id) const
@@ -455,7 +463,7 @@ QMatrix QSvgTinyDocument::matrixForElement(const QString &id) const
t *= node->m_style.transform->qtransform();
node = node->parent();
}
-
+
return t.toAffine();
}
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
index 553838e..5b359b9 100644
--- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
+++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
@@ -77,6 +77,7 @@ private slots:
void testUseElement();
void smallFont();
void styleSheet();
+ void duplicateStyleId();
#ifndef QT_NO_COMPRESS
void testGzLoading();
@@ -139,22 +140,28 @@ void tst_QSvgRenderer::invalidUrl_data()
{
QTest::addColumn<QByteArray>("svg");
- QTest::newRow("00") << QByteArray("<svg><circle fill=\"url\" /></svg>");
- QTest::newRow("01") << QByteArray("<svg><circle fill=\"url0\" /></svg>");
- QTest::newRow("02") << QByteArray("<svg><circle fill=\"url(0\" /></svg>");
- QTest::newRow("03") << QByteArray("<svg><circle fill=\"url (0\" /></svg>");
- QTest::newRow("04") << QByteArray("<svg><circle fill=\"url ( 0\" /></svg>");
- QTest::newRow("05") << QByteArray("<svg><circle fill=\"url#\" /></svg>");
- QTest::newRow("06") << QByteArray("<svg><circle fill=\"url#(\" /></svg>");
- QTest::newRow("07") << QByteArray("<svg><circle fill=\"url(#\" /></svg>");
- QTest::newRow("08") << QByteArray("<svg><circle fill=\"url(# \" /></svg>");
- QTest::newRow("09") << QByteArray("<svg><circle fill=\"url(# 0\" /></svg>");
+ QTest::newRow("01") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url0\" /></svg>");
+ QTest::newRow("02") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url(0\" /></svg>");
+ QTest::newRow("03") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url (0\" /></svg>");
+ QTest::newRow("04") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url ( 0\" /></svg>");
+ QTest::newRow("05") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url#\" /></svg>");
+ QTest::newRow("06") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url#(\" /></svg>");
+ QTest::newRow("07") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url(#\" /></svg>");
+ QTest::newRow("08") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url(# \" /></svg>");
+ QTest::newRow("09") << QByteArray("<svg><linearGradient id=\"0\"/><circle fill=\"url(# 0\" /></svg>");
+ QTest::newRow("10") << QByteArray("<svg><linearGradient id=\"blabla\"/><circle fill=\"urlblabla\" /></svg>");
+ QTest::newRow("11") << QByteArray("<svg><linearGradient id=\"blabla\"/><circle fill=\"url(blabla\" /></svg>");
+ QTest::newRow("12") << QByteArray("<svg><linearGradient id=\"blabla\"/><circle fill=\"url(blabla)\" /></svg>");
+ QTest::newRow("13") << QByteArray("<svg><linearGradient id=\"blabla\"/><circle fill=\"url(#blabla\" /></svg>");
}
void tst_QSvgRenderer::invalidUrl()
{
QFETCH(QByteArray, svg);
+#if QT_CONFIG(regularexpression)
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Could not resolve property"));
+#endif
QSvgRenderer renderer(svg);
QVERIFY(renderer.isValid());
}
@@ -1459,5 +1466,17 @@ void tst_QSvgRenderer::styleSheet()
QCOMPARE(images[0], images[1]);
}
+void tst_QSvgRenderer::duplicateStyleId()
+{
+ QByteArray svg = QByteArrayLiteral("<svg><linearGradient id=\"a\"/>"
+ "<rect style=\"fill:url(#a)\"/>"
+ "<linearGradient id=\"a\"/></svg>");
+ QTest::ignoreMessage(QtWarningMsg, "Duplicate unique style id: \"a\"");
+ QImage image(200, 200, QImage::Format_RGB32);
+ QPainter painter(&image);
+ QSvgRenderer renderer(svg);
+ renderer.render(&painter);
+}
+
QTEST_MAIN(tst_QSvgRenderer)
#include "tst_qsvgrenderer.moc"