diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2016-06-29 23:12:55 +0100 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2016-06-29 23:25:30 +0100 |
commit | 5f92810f761e7df7b1f03e916535ad8b4ce6c08c (patch) | |
tree | 54c509e1f677cec991108e9757debbe3fa6b29c8 | |
parent | 34e12fcb38bb9e555116a89a2f6813dd402aaa08 (diff) | |
download | deluge-5f92810f761e7df7b1f03e916535ad8b4ce6c08c.tar.gz deluge-5f92810f761e7df7b1f03e916535ad8b4ce6c08c.tar.bz2 deluge-5f92810f761e7df7b1f03e916535ad8b4ce6c08c.zip |
[#2784] [Execute] Escape ampersand in args for Windows
Due to the nature of passing a command and args to cmd.exe and then
to a batch file in Windows any ampersands in execute args need to be
double-escaped so prefixing with tripe-caret (^^^&) is the fix for this.
-rw-r--r-- | deluge/plugins/execute/execute/core.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/deluge/plugins/execute/execute/core.py b/deluge/plugins/execute/execute/core.py index 4ba00e74d..31ae67467 100644 --- a/deluge/plugins/execute/execute/core.py +++ b/deluge/plugins/execute/execute/core.py @@ -44,7 +44,7 @@ import deluge.component as component from deluge.configmanager import ConfigManager from deluge.core.rpcserver import export from deluge.event import DelugeEvent -from deluge.common import utf8_encoded +from deluge.common import utf8_encoded, windows_check DEFAULT_CONFIG = { @@ -140,9 +140,15 @@ class Core(CorePluginBase): if command[EXECUTE_EVENT] == event: command = os.path.expandvars(command[EXECUTE_COMMAND]) command = os.path.expanduser(command) + + cmd_args = [torrent_id, torrent_name, save_path] + if windows_check: + # Escape ampersand on windows (see #2784) + cmd_args = [arg.replace("&", "^^^&") for arg in cmd_args] + if os.path.isfile(command) and os.access(command, os.X_OK): - log.debug("[execute] Running %s", command) - d = getProcessOutputAndValue(command, (torrent_id, torrent_name, save_path), env=os.environ) + log.debug("[execute] Running %s with args: %s", command, cmd_args) + d = getProcessOutputAndValue(command, cmd_args, env=os.environ) d.addCallback(log_error, command) else: log.error("[execute] Execute script not found or not executable") |