diff options
author | Axel Spoerl <axel.spoerl@qt.io> | 2023-04-18 13:44:00 +0200 |
---|---|---|
committer | Axel Spoerl <axel.spoerl@qt.io> | 2023-04-24 21:49:29 +0200 |
commit | 11f14c3b0dee239644097b3eddbbf464e4d69600 (patch) | |
tree | 43f4a43b1eb78bcdbf60ad9d4b653967a1f9cb61 /src/xml | |
parent | 3fd7086878ea03861fc82348fc5b4e77f76b2a86 (diff) |
QDomDocument: no longer drop a provided 'standalone' attribute if 'no'
- Definition of 'standalone' attribute:
An XML declaration containing the attribute 'standalone' with its
value set to 'yes', tells the parser to ignore markup declarations
in the DTD and to use them only for validation.
The declaration attribute is optional and defaults to 'no'.
- Behavior Qt5
In qt5, DOM documents contained the standalone attribute,
regardless of whether or not it was explicitly specified.
- Behavior Qt6
In Qt6, the standalone attribute was only contained in a DOM document,
if its value was 'yes'. If it was explicitly declared with the value
being 'no', it was dropped in the DOM document.
- Expected behavior
If the source specified it overtly, then the generated XML should
contain the attribute, even when it takes its default value.
- Code base
QXmlStreamReader provides a public bool getter isStandaloneDocument().
This says whether the document is standalone or not.
The information whether the attribute was actually specified gets lost.
In consequence, the attribute was always dropped on non-standalone
documents.
- Fix
This patch makes hasStandalone a member of QXmlStreamReaderPrivate, to
record whether the attribute has been explicitly specified.
QDomParser is modified to retain the standalone attribute, if
QXmlStreamReaderPrivate::hasStandalone is true.
- Test
The patch adds a test function in tst_QDom.
Fixes: QTBUG-111200
Pick-to: 6.5 6.2
Change-Id: I06a0f230a2d69597dd6453f8fd3b036943d08735
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/xml')
-rw-r--r-- | src/xml/dom/qdomhelpers.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/xml/dom/qdomhelpers.cpp b/src/xml/dom/qdomhelpers.cpp index 62258fbdfd..48869907f8 100644 --- a/src/xml/dom/qdomhelpers.cpp +++ b/src/xml/dom/qdomhelpers.cpp @@ -8,6 +8,7 @@ #include "qdomhelpers_p.h" #include "qdom_p.h" #include "qxmlstream.h" +#include "private/qxmlstream_p.h" #include <memory> #include <stack> @@ -264,9 +265,10 @@ bool QDomParser::parseProlog() if (reader->isStandaloneDocument()) { value += u" standalone='yes'"_s; } else { - // TODO: Add standalone='no', if 'standalone' is specified. With the current - // QXmlStreamReader there is no way to figure out if it was specified or not. - // QXmlStreamReader needs to be modified for handling that case correctly. + // Add the standalone attribute only if it was specified + QXmlStreamReaderPrivate *priv = QXmlStreamReaderPrivate::get(reader); + if (priv->hasStandalone) + value += u" standalone='no'"_s; } if (!domBuilder.processingInstruction(u"xml"_s, value)) { |