Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-16020

QDom* family saves some XML invalid characters unescaped by calling toString() method

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.7.1
    • XML: DOM
    • None
    • Win7, MSVC++ 2010 EE

    Description

      QDom* saving mechanism doesn't escape '(apostrophe) and >(greater) characters when perform saving an XML tree into a document by calling toString() method.
      Obviously it is a bug in the escaping procedure.
      Code for reproducing:

      #include <QDomElement>
      #include <QDomText>
      #include <QDomDocument>
      #include <QCoreApplication>
      #include <QtDebug>
      
      int main(int argc, char** argv) 
      {
          QCoreApplication App(argc, argv);
          QDomDocument XMLContent;
          XMLContent.appendChild(XMLContent.createProcessingInstruction("xml",  "version=\"1.0\" encoding=\"utf-8\""));
          QDomElement NewNode = XMLContent.createElement("element");
          NewNode.setAttribute("attribute", "<>&'\"");
          QDomText NewText = XMLContent.createTextNode("<>&'\"");
          NewNode.appendChild(NewText);
          XMLContent.appendChild(NewNode);
          qDebug() << XMLContent.toString();
          
          return App.exec();
      }
      

      It displays:

      "<?xml version="1.0" encoding="utf-8"?>
      <element attribute="&lt;>&amp;'&quot;">&lt;>&amp;'"</element>
      "

      but it should display:

      "<?xml version="1.0" encoding="utf-8"?>
      <element attribute="&lt;&gt;&amp;&apos;&quot;">&lt;&gt;&amp;&apos;&quot;</element>
      "

      Here is the responsible procedure:

      static QString encodeText(const QString &str,
                                QTextStream &s,
                                const bool encodeQuotes = true,
                                const bool performAVN = false,
                                const bool encodeEOLs = false)
      {
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            phartman Peter Hartmann (closed Nokia identity) (Inactive)
            ixsci Eugene Shcherbina
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes