qBittorrent
qBittorrent copied to clipboard
Unable to correctly handle arguments when using "Run external program on torrent completion"
qBittorrent version and Operating System
non-Windows
If on linux, libtorrent-rasterbar and Qt version
All versions (tested using archlinux, libtorrent-rasterbar 1.2.5, qt 5.14 1)
What is the problem
As we can see the execution procedure in the code when using non-windows OS:
https://github.com/qbittorrent/qBittorrent/blob/3c17ad566c94a92b6beefae119db3da5cb26456e/src/app/application.cpp#L307-L309
https://github.com/qbittorrent/qBittorrent/blob/3c17ad566c94a92b6beefae119db3da5cb26456e/src/app/application.cpp#L326-L328
https://github.com/qbittorrent/qBittorrent/blob/3c17ad566c94a92b6beefae119db3da5cb26456e/src/app/application.cpp#L330-L333
https://github.com/qbittorrent/qBittorrent/blob/3c17ad566c94a92b6beefae119db3da5cb26456e/src/app/application.cpp#L384
The parameter is just simply replaced without any quote. This will work fine in most cases, except some of them have ". For example, when %L is abc" def "ghi it is impossible to pass this as one parameter to the external program, even if the external program settings is quoted by the user like extprogram "%L".
Steps to reproduce
- Write a sh script names
extprogramlike this:
#!/bin/sh
echo "$#" > /tmp/testarg
- Set "Run external program on torrent completion" as
/path/to/extprogram "%L". - Complete a torrent with categorie like
abc" def "ghi. - Check the content in
/tmp/testarg.
What is the expected behaviour
1
What is the current behaviour
3
Extra info
According to the official QT Document https://doc.qt.io/qt-5/qprocess.html#start-1:
Literal quotes in the command string are represented by triple quotes. For example:
QProcess process; process.start("dir \"Epic 12\"\"\" Singles\"");
So we should add an additional procedure to handle this case.
My suggestion is to replace quoted labels before replacing the unquoted labels.
QString program = Preferences::instance()->getAutoRunProgram().trimmed();
QString tmp = torrent->name();
tmp.replace("\"","\"\"\"");
tmp.insert(0,"\"");
tmp.append("\"");
program.replace("\"%N\"", tmp);
if(!tmp.contains("%N", Qt::CaseSensitive))
program.replace("%N", torrent->name());
It is not perfect for all situations(such as /path/to/extprogram "abc%L"). And may have performance issue. But it is sufficient for almost all needs.
Also, the current implementation has problem that if torrent name contains %L, it will be replaced by category name. So fix this issue is something complicated. I can make a pull request about fixing this problem if you accept my opinion.
-
This ticket has been closed due to being "out-of-date", and thus either most likely resolved in recent versions or no longer applicable.
-
If you experience the reported problem or similar in the latest version, please open a new issue report with the requested information in the issue template.
-
A new issue report with relevant updated data gathered from the latest version is preferable to necroing an old report with a comment like "still happens in version x.y.z", even if you think the bug is the same, or suspect of a regression. Due to the changes made to the qBittorrent code and its dependencies over time, the exact cause of your problem could be totally different than the original one, despite the visible symptoms of the bug being similar. Thus, providing relevant updated information is crucial to find and fix the root cause of a recurrent problem or regression.
-
Thank you for your contribution(s).