[vlc-commits] [Git][videolan/vlc][master] 4 commits: qt: fix `QUrl` getting converted to `QString` only to be converted to `QUrl` again

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Apr 1 07:46:09 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
c8d6c1d7 by Fatih Uzunoglu at 2025-04-01T07:30:24+00:00
qt: fix `QUrl` getting converted to `QString` only to be converted to `QUrl` again

When a variant stores `QUrl`, `QVariant::canConvert<QString>()` returns `true`. This
means that it is always converted to a string.

If the media is provided as `QUrl`, it should not be converted to string first.

- - - - -
97809421 by Fatih Uzunoglu at 2025-04-01T07:30:24+00:00
qt: reject invalid urls in `toMediaList()`

- - - - -
9b011d41 by Fatih Uzunoglu at 2025-04-01T07:30:24+00:00
qt: do not feed the playlist with null items

- - - - -
64b29135 by Fatih Uzunoglu at 2025-04-01T07:30:24+00:00
qt: use `vlc_uri2path()` instead of `QUrl::fromUserInput()` and do not resolve symbolic links in the interface

- - - - -


1 changed file:

- modules/gui/qt/playlist/playlist_controller.cpp


Changes:

=====================================
modules/gui/qt/playlist/playlist_controller.cpp
=====================================
@@ -52,32 +52,43 @@ static QVector<RAW> toRaw(const QVector<WRAPPER> &items)
     return vec;
 }
 
-static QUrl resolveWinSymlinks(const QUrl &mrl)
-{
-#ifdef _WIN32
-    QFileInfo info (mrl.toLocalFile());
-    if ( info.isSymLink() )
-    {
-        QString target = info.symLinkTarget();
-        return QFile::exists(target) ? QUrl::fromLocalFile(target) : mrl;
-    }
-#endif
-    return mrl;
-}
-
 QVector<Media> toMediaList(const QVariantList &sources)
 {
     QVector<Media> mediaList;
     std::transform(sources.begin(), sources.end(),
                    std::back_inserter(mediaList), [](const QVariant& value) {
-        if (value.canConvert<QUrl>() || value.canConvert<QString>())
+        const auto typeId = value.typeId();
+        if ((typeId == QMetaType::QUrl) || (typeId == QMetaType::QString))
         {
-            QUrl mrl = value.canConvert<QString>()
-                    ? QUrl::fromUserInput(value.value<QString>())
-                    : value.value<QUrl>();
+            std::optional<QString> input;
+            QUrl mrl;
+            if (typeId == QMetaType::QString)
+            {
+                input = value.value<QString>().trimmed(); // akin to `UrlValidator::fixup()`
+                mrl = *input; // plain text to QUrl, tolerant mode
+            }
+            else if (typeId == QMetaType::QUrl)
+            {
+                mrl = value.value<QUrl>(); // use the provided QUrl as is
+            }
+            else
+                Q_UNREACHABLE();
 
-            if (mrl.isLocalFile())
-                mrl = resolveWinSymlinks(mrl);
+            if (!mrl.isValid())
+                return Media(); // the input is broken (beyond repair of tolerant mode if plain text)
+
+            if ((typeId == QMetaType::QString) && mrl.scheme().isEmpty())
+            {
+                // Assume input is a path (only if the input is plain text):
+                assert(input);
+                mrl = QString::fromUtf8(vlc::wrap_cptr(vlc_path2uri(input->toUtf8().cbegin(), nullptr)).get()); // tolerant mode
+
+                if (!mrl.isValid())
+                    return Media();
+            }
+
+            if (mrl.scheme().isEmpty()) // akin to `UrlValidator::validate()`
+                return Media();
 
             return Media(mrl.toString(QUrl::FullyEncoded), mrl.fileName());
         }
@@ -92,6 +103,9 @@ QVector<Media> toMediaList(const QVariantList &sources)
         return Media{};
     });
 
+    // Clear invalid media:
+    mediaList.removeAll(Media());
+
     return mediaList;
 }
 
@@ -421,6 +435,9 @@ PlaylistController::append(const QVector<Media> &media, bool startPlaying)
 {
     Q_D(PlaylistController);
 
+    if (Q_UNLIKELY(media.isEmpty()))
+        return;
+
     vlc_playlist_locker locker(d->m_playlist);
 
     auto rawMedia = toRaw<input_item_t *>(media);
@@ -445,6 +462,10 @@ void
 PlaylistController::insert(size_t index, const QVector<Media> &media, bool startPlaying)
 {
     Q_D(PlaylistController);
+
+    if (Q_UNLIKELY(media.isEmpty()))
+        return;
+
     vlc_playlist_locker locker(d->m_playlist);
 
     auto rawMedia = toRaw<input_item_t *>(media);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e4be71d6efc69d5d3d97cfef8093322d1d740faa...64b29135d4fd725edf350d7cae398b86479f2efc

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e4be71d6efc69d5d3d97cfef8093322d1d740faa...64b29135d4fd725edf350d7cae398b86479f2efc
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list