shell2http icon indicating copy to clipboard operation
shell2http copied to clipboard

Passing Spaces in `$v_params` to Command

Open AugustSaintFreytag opened this issue 3 years ago • 3 comments
trafficstars

Running the utility in --form mode, I’m trying to write a simple passthrough, essentially in the form of:

shell2http --form --no-index --port=$PORT /exec './my-utility $v_args'

The way $v_name currently works presents multiple issues I found while tinkering with this:

  • Using double quotes for the command causes v_args to be expanded immediately and shell2http will no longer substitute for obvious reasons.
  • Because the v_args needs to be preserved as is, it’s not possible to use other env vars, e.g. a UTIL_PATH to the utility that should be called here. Only implicitly used variables (like $PATH) can be used.
  • If v_args contains spaces after URI component decoding, content is cut off.

As an example, building an /mkdir 'mkdir $v_args' with an argument containing spaces ("my dir") and playing around with quotation yields all variations of /my, /'my, /"my, and my favourite, /$v_args, but never actually creates a /my dir.

I’m in a spot where it seems most sensible to use some sort of additional coding and passing that to a proxy first; this could be a shell script that takes encoded v_args in, decodes spaces and other possibly conflicting characters and only then calls the intended utility. However, this clashes with the simplicity that led me to shell2http in the first place.

AugustSaintFreytag avatar Feb 22 '22 11:02 AugustSaintFreytag

Sorry, response may be delayed, we have a war, russia attacked my country.

msoap avatar Mar 09 '22 10:03 msoap

If there's anything us random internet geeks can do to help, do let us know :(

srd424 avatar Mar 09 '22 10:03 srd424

Hi @AugustSaintFreytag,

shell quoting is hard 🙂

for using var in-place you need single quotes, and for values with spaces you need double quotes, something like this:

shell2http -form /md 'mkdir "$v_args"'

and:

curl 'http://localhost:8080/md?args=111+232'

but sometimes it is more convenient to use a separate script, where quoting can be easier:

shell2http -form /md ./script.sh

msoap avatar May 15 '22 20:05 msoap