From f440fa9dbd8a7e08a279bef230dee9eb168a93dc Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 24 Jan 2021 22:35:27 -0600 Subject: [PATCH] Add the standard-defined "xml" namespace if it is not specified The XML standard stipulates: The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared, and MUST NOT be bound to any other namespace name. Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace. If the document does not explicitly include this namespace, it is added. This prevents errors due to the use of the namespace in some imported SVG files. In debug builds those errors emit warning messages, and in Windows debug builds those errors cause an abort() to be called. --- src/Mod/TechDraw/App/QDomNodeModel.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Mod/TechDraw/App/QDomNodeModel.cpp b/src/Mod/TechDraw/App/QDomNodeModel.cpp index 1ecfa48d04..25a704a174 100644 --- a/src/Mod/TechDraw/App/QDomNodeModel.cpp +++ b/src/Mod/TechDraw/App/QDomNodeModel.cpp @@ -195,9 +195,10 @@ QXmlName QDomNodeModel::name ( const QXmlNodeModelIndex & ni ) const return QXmlName(m_Pool, n.nodeName(), QString(), QString()); } -QVector QDomNodeModel::namespaceBindings(const QXmlNodeModelIndex & ni ) const +QVector QDomNodeModel::namespaceBindings(const QXmlNodeModelIndex & ni) const { QDomNode n = toDomNode(ni); + bool xmlNamespaceWasDefined = false; QVector res; while (!n.isNull()) @@ -219,14 +220,27 @@ QVector QDomNodeModel::namespaceBindings(const QXmlNodeModelIndex & ni for (x = 0; x < res.size(); ++x) if (res.at(x).prefix(m_Pool) == p) break; - if (x >= res.size()) + if (x >= res.size()) { res.append(QXmlName(m_Pool, QString::fromUtf8("xmlns"), attrs.item(i).nodeValue(), p)); - } + if (p == QString::fromLatin1("xml")) + xmlNamespaceWasDefined = true; + } + } } n = n.parentNode(); } + // Per the XML standard: + // "The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but + // need not, be declared, and MUST NOT be bound to any other namespace name. Other prefixes MUST NOT be bound to + // this namespace name, and it MUST NOT be declared as the default namespace." + // + // If the document does not specifically include this namespace, add it now: + if (!xmlNamespaceWasDefined) { + res.append(QXmlName(m_Pool, QString::fromUtf8("xmlns"), QString::fromLatin1("http://www.w3.org/XML/1998/namespace"), QString::fromLatin1("xml"))); + } + return res; }