Safe filepath processing at new torrent content selection

Review Request #130052 - Created March 27, 2017 and submitted

Alexander Trufanov

Today I've tried to create a torrent file with current KT build that contains a directory. And got something like this.

The name of torrent is empty and the root subfolder is empty too. I have debugged this and found out that name argument that passed to libktorrent's TorrentCreator() is empty. This is due to lack of filename check on KTorrent side.
Perhaps KUrlRequester is currently not working as expected on my machine, perhaps this is because i'm selecting directories by browsing inside them and pressing Open button while nothing else is selected, but my KUrlRequester m_url always returns path to directory with trailing slash. Like /tmp/1/. In this case QUrl::fileName() returns empty string. And surprisingly there is no any validation of this value. Also user can just type in path to directory with trailing slash.
Thus I suggest more accurate name processing by replacing
QString name = url.fileName();

QString name = url.toLocalFile();
name = QFileInfo(name).isDir() ? QDir(name).dirName() : url.fileName();

it'll return proper name for any local filepath except someone select root folder itself - in this case name will be empty.

Alexander Trufanov
Albert Astals Cid
Albert Astals Cid
Alexander Trufanov
Review request changed

Status: Closed (submitted)

Change Summary:

Submitted with commit 4907278a935276e449fd20cdaa1370e4d48cb58c by Alexander Trufanov to branch master.