aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2025-12-09 08:44:20 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2025-12-09 09:40:42 +0100
commit9e8a648a96ce1e2c901b92938c96a3ba5eb10f4e (patch)
tree8e49c15174ebccb1ea28f558fd47caa6f471adeb /src
parentcfc3e783fed4e876c2c29d008b5ef43c547b16b7 (diff)
VectorImage: Escape quotes in font families
Loading SVG files that use font families with quotes will produce invalid output that does not parse correctly. When outputting the font family, we have to escape the quotes first. In addition, any character in the font family has to be valid HTML when we output it into a style tag. Pick-to: 6.8 6.10 6.11 Change-Id: If25b3cfd3a537d7f7c8c65045deece1ad02b43c3 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quickvectorimage/generator/qquickqmlgenerator.cpp13
-rw-r--r--src/quickvectorimage/generator/qsvgvisitorimpl.cpp2
2 files changed, 10 insertions, 5 deletions
diff --git a/src/quickvectorimage/generator/qquickqmlgenerator.cpp b/src/quickvectorimage/generator/qquickqmlgenerator.cpp
index 734e5c8f2b..a7bafb2be5 100644
--- a/src/quickvectorimage/generator/qquickqmlgenerator.cpp
+++ b/src/quickvectorimage/generator/qquickqmlgenerator.cpp
@@ -19,6 +19,13 @@
QT_BEGIN_NAMESPACE
+static QString sanitizeString(const QString &input)
+{
+ QString s = input;
+ s.replace(QLatin1Char('"'), QLatin1String("\\\""));
+ return s;
+}
+
QQuickQmlGenerator::QQuickQmlGenerator(const QString fileName, QQuickVectorImageGenerator::GeneratorFlags flags, const QString &outFileName)
: QQuickGenerator(fileName, flags)
, outputFileName(outFileName)
@@ -964,10 +971,8 @@ void QQuickQmlGenerator::generateTextNode(const TextNodeInfo &info)
stream() << "color: \"" << info.fillColor.defaultValue().value<QColor>().name(QColor::HexArgb) << "\"";
stream() << "textFormat:" << (info.needsRichText ? "Text.RichText" : "Text.StyledText");
- QString s = info.text;
- s.replace(QLatin1Char('"'), QLatin1String("\\\""));
- stream() << "text: \"" << s << "\"";
- stream() << "font.family: \"" << info.font.family() << "\"";
+ stream() << "text: \"" << sanitizeString(info.text) << "\"";
+ stream() << "font.family: \"" << sanitizeString(info.font.family()) << "\"";
if (info.font.pixelSize() > 0)
stream() << "font.pixelSize:" << info.font.pixelSize();
else if (info.font.pointSize() > 0)
diff --git a/src/quickvectorimage/generator/qsvgvisitorimpl.cpp b/src/quickvectorimage/generator/qsvgvisitorimpl.cpp
index 38f8bb4369..3193bf05d4 100644
--- a/src/quickvectorimage/generator/qsvgvisitorimpl.cpp
+++ b/src/quickvectorimage/generator/qsvgvisitorimpl.cpp
@@ -799,7 +799,7 @@ void QSvgVisitorImpl::visitTextNode(const QSvgText *node)
needsRichText = needsRichText || !styleTagContent.isEmpty();
if (!styleTagContent.isEmpty())
- text += QStringLiteral("<span style=\"%1\">").arg(styleTagContent);
+ text += QStringLiteral("<span style=\"%1\">").arg(styleTagContent.toHtmlEscaped());
if (font.resolveMask() & QFont::WeightResolved && font.bold())
text += QStringLiteral("<b>");