aestasit/sshoogr — pull request #54 by nthykier (2014-09-22 19:17:01+00:00)
Title: Feature/single cmd

This patch series adds a new "execCmd" method to SessionDelegate, which (unlike exec) executes a single command. Given a list of strings, it (optionally) quotes each string and combines them into a command line that executes one remote command with 0 or more arguments.

Quoting is done using single quotes in an "sh" compatible way. On the plus side it is highly reliable and covers every metacharacter. On the downside, quoting a string containing a single quote quickly becomes unreadable as nothing inside single quotes can be escaped - i.e. a litteral ' inside a string generally be escaped via the 3-character sequences '\'' (that is, terminate the current quote, escape a single quote and start a new quote for the rest of the string).

To make commands more readable, arguments are only quoted when necessary (using a whitelist of "safe" characters to err on the side of correctness/safety). This whitelist considers of the following ASCII characters: All letters in the alphabeth, digts and the following symbols +-/_^,.=.

The execCmd forwards everything to doExec and accordingly supports all existing features of exec (except for the differences in interpreting the "command" argument).