-
-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exec expansion splits args based on space after variable expansion #171
Comments
Technically speaking, this issue hasn't been fixed, rather just circumvented in a specific use-case. To fix this properly, I'd steer away from the native .Split method, and instead use a custom splitting function which will take care of an escape character and handle it that way. Here's my implementation in Python:
Then when you replace the template, you wrap the new value around in quotes and escape inner quotes by replacing " with " and finally pass it on to the custom splitting function. That way arguments the forwarded properly to exec.Command. On the other hand, this should be a moderately rare use-case, so even if we don't handle it properly, it shouldn't really be a problem, as it can ultimately be circumvented in other ways. Still, might be good to hear other people's opinions on this. |
Another way to go at this issue is to have each argument go into a separate input field (UI-wise), and on the backend side, each input field is separately parsed ("processed") and it's passed directly as an array to exec.Command. However, I don't know if this breaks something? This may be a bit more work frontend-wise, but leaves the burden off the backend. |
Discussed on discord - just a quick summary here because I'm likely going to forget.
brr Exec currently does not support spaces within quotes, and passes them as individual args. Because of the ordering of the macro expansion
autobrr/internal/action/exec.go
Line 26 in 5a45851
into the arg string split
autobrr/internal/action/exec.go
Line 33 in 5a45851
it is impossible to pass arguments and macros containing a space to programs. Invoking a script is a current workaround, because $SHELL can repair the damage by bringing the arg string together again by wrapping in quotes. Changing this ordering can help, but the implementation will still be incorrect as expected spaces (even if escaped) will be split.
STR: "{{ .TorrentName }}" >
Sally Goes to the Mall S04E29
> curl -XPOSTThere's a couple ways to tackle this, an out-of-tree one being https://github.com/mattn/go-shellwords which could add the ability to have environment variables as well on execution.
The text was updated successfully, but these errors were encountered: