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

QMimeData::setData("text/uri-list",…) loses last url

    XMLWordPrintable

Details

    • 038c199d5 (dev), 82b2436d4 (6.7)

    Description

      reproduce steps:

      1. create u.cpp:

      u.cpp
      #include <QMimeData>
      #include <QUrl>
      
      int main(void){
      	QMimeData m;
      	m.setData("text/uri-list","https://example.com/\nhttps://example.net/\nhttps://example.org/");
      	QList<QUrl> urls=m.urls();
      	QByteArray b;
      	for(size_t i=0,len=urls.size();i<len;++i){
      		b.append(urls[i].toEncoded());
      		b.append('\n');
      	}
      	fwrite(b.constData(),1,b.size(),stdout);
      }
      

      2. run:

      g++ \
      u.cpp \
      -o u \
      -O0 \
      -ggdb \
      -I/usr/include/x86_64-linux-gnu/qt6 \
      -I/usr/include/x86_64-linux-gnu/qt6/QtCore \
      -lQt6Core
      

      3. run:

      ./u
      

      real output:

      https://example.com/
      https://example.net/
      

      expected output:

      https://example.com/
      https://example.net/
      https://example.org/
      

      I think bug is in this function in qmimedata.cpp (while loop body never runs if '\n' not found):

      static QList<QVariant> dataToUrls(QByteArrayView text)
      {
          QList<QVariant> list;
          qsizetype newLineIndex = -1;
          qsizetype from = 0;
          const char *begin = text.data();
          while ((newLineIndex = text.indexOf('\n', from)) != -1) {
              const auto bav = QByteArrayView(begin + from, begin + newLineIndex).trimmed();
              if (!bav.isEmpty())
                  list.push_back(QUrl::fromEncoded(bav));
              from = newLineIndex + 1;
              if (from >= text.size())
                  break;
          }
          return list;
      }
      

      Attachments

        For Gerrit Dashboard: QTBUG-124580
        # Subject Branch Project Status CR V

        Activity

          People

            thiago Thiago Macieira
            bzzzz BZZZZ DZZZZ
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes