Skip to content
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

Handle single quotes in 'darling shell' #906

Merged
merged 1 commit into from Feb 9, 2021

Conversation

bemoody
Copy link
Contributor

@bemoody bemoody commented Dec 22, 2020

If the command-line arguments to darling shell include single quotes, they must be escaped when constructing the string that is sent to shellspawn.

(Only single quotes need special handling; all other characters, including backslashes and control characters, are treated literally within single-quoted strings.)

For example, running the command

$ darling shell sh -c "echo 'hello world'"

would result in the following string being sent to the shell:

'sh' '-c' 'echo 'hello world''

(which is interpreted as a command with three arguments: "-c", "echo hello", and "world").

What we want instead is:

'sh' '-c' 'echo '\''hello world'\'''

(which is interpreted as a command with two arguments: "-c" and "echo 'hello world'".)

If the command-line arguments to 'darling shell' include single
quotes, they must be escaped when constructing the string that is sent
to shellspawn.

For example, the command:

    darling shell sh -c "echo 'hello world'"

must be escaped as:

    'sh' '-c' 'echo '\''hello world'\'''

rather than:

    'sh' '-c' 'echo 'hello world''
@HinTak
Copy link
Contributor

HinTak commented Dec 22, 2020

Or put it in a file and run it? It is easier than piling on multiple escapes through multiple stages.

@HinTak
Copy link
Contributor

HinTak commented Dec 22, 2020

The problem is that the argument is interpreted twice - by the host's shell then by darling running the darling version of shell. If you put the content in a file it is run by darling's version only.

You get the same problem on the host os by doing sh -c sh -c echo ...

@HinTak
Copy link
Contributor

HinTak commented Dec 22, 2020

I don't think this should be merged - even the host shell does not support sh -c sh -c echo ....

@bemoody
Copy link
Contributor Author

bemoody commented Dec 22, 2020 via email

@bugaevc
Copy link
Member

bugaevc commented Dec 23, 2020

Makes sense to me.

even the host shell does not support sh -c sh -c echo ....

@HinTak But sh is not supposed to be invoked like sh command arg arg..., it's supposed to be invoked either as sh ./script.sh, or as sc -c "command arg arg..."

darling shell, on the other hand, is supposed to be invoked as darling shell command arg arg...; and what that does is it calls sh -c "'command' 'arg' 'arg' '...'" inside the container. We quote the arguments, so it makes sense to escape them properly.

@ahyattdev ahyattdev merged commit d8d618f into darlinghq:master Feb 9, 2021
@ahyattdev
Copy link
Member

looks good to me @bemoody

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants