sfackler / shell-escape

Apache License 2.0
20 stars 6 forks source link

overload unix::escape to be useable with Cow<[u8]> #4

Open fbenkstein opened 6 years ago

fbenkstein commented 6 years ago

Unix paths are not necessarily UTF-8 so a generic way to escape them is useful. Overload unix::escape through private trait UnixEscape so it can be used with both Cow<str> and Cow<[u8]>.

fbenkstein commented 6 years ago

Does this have a chance of being merged? I understand if you think it adds to much complexity, I'll just roll my own module then.

sfackler commented 6 years ago

Can shells deal with non-ASCII bytes with the normal ' quoting or do they need to be further escaped into an octal sequence or something like that?

fbenkstein commented 6 years ago

I think non-ascii bytes do not need to be escaped. I‘ll do some research to come up with some evidence.

fbenkstein commented 6 years ago

The way I read http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html is that only | & ; < > ( ) $ ` \ " ' <space> <tab> <newline> * ? [ # ˜ = % need to be quoted. As for non-ascii, I believe that http://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap06.html says that (assuming the character set is ASCII based) the non-ascii characters just represent themselves without any need for escaping.

fbenkstein commented 6 years ago

I could add an integration test. For example, we could create a file in a temporary directory, call $SHELL -c "rm $filename", and then check that the file really was deleted for various values of $SHELL and $filename (and maybe even different locale settings to ensure correct behavior.