-
Notifications
You must be signed in to change notification settings - Fork 321
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
scan.go: scan() shall support adjacent quoting #267
Comments
@dumblob Quotes in |
Yeah, I saw the implementation, but I'm unable to find a way for the described issue. It also doesn't sound right to me to list all special cases (e.g. escape all control characters cmd c1 &{{ lf -remote 'send '"$id"' select "'"$(sed -Ez -e 's|('"'"')|"\1"|g' -e 's|(\\)|"134"|g' -e '...for_each_ctrl_char' <<END
$f
END
)"'"' }} (not even sure the code above will work) as that's really not nice and in addition it's fragile (e.g. if |
@dumblob How does concatenating strings solve the example you provided? |
One can easily guarantee (in a forward compatible manner) no control character nor any quote will get interpreted by something like: cmd c1 &{{ lf -remote "send $id select '$( sed -Ez "s|'|'\"'\"'|g" <<END
$f
END
printf "'" # this is to overcome subshell removing all trailing newlines (in case filename has trailing newline(s)
)" }} I.e. filename |
@dumblob I still don't understand. You only escaped |
The point is, that if one is inside of |
@dumblob What about the control characters then? |
Inside of anything enclosed in single apostrophes ( Lines 260 to 268 in 3c5abbb
|
@dumblob Weren't you trying to handle control characters in filenames? That is what you told in the beginning of the issue. If that's the case, why are you trying this with single quotes rather than double quotes? |
I meant control characters |
Is there any better way than to support all currently implemented lf control characters as outlined above? Let me demonstrate the issue with pure Go code. s := "/path/with'so me/sep\" arat e's ingle'and double\" qu otes \"and arbitrary spaces"
//cmd := exec.Command( "lf", "-remote", "send 1234 select " + s ) // wrong
//cmd := exec.Command( "lf", "-remote", "send 1234 select '" + s + "'" ) // also wrong (actually impossible to achieve with single quotes at all)
//cmd := exec.Command( "lf", "-remote", "send 1234 select \"" + s + "\"" ) // also wrong (escaping of " and all control sequences is missing)
s = strings.ReplaceAll( s, "\\", "\\\\" )
s = strings.ReplaceAll( s, "\"", "\\\"" )
cmd := exec.Command( "lf", "-remote", "send 1234 select \"" + s + "\"" ) // finally right With my proposal above this would be simpler and more forward compatible (I can imagine lf escape sequences changing or being extended, but I can't imagine the adjacent functionality being removed or changed): s = strings.ReplaceAll( s, "'", "'\"'\"'" )
cmd := exec.Command( "lf", "-remote", "send 1234 select '" + s + "'" ) Shouldn't this issue stay open? |
Currently it's impossible to write e.g.
:select 'my'""'file'
(not even:select 'my''file'
) to select the filemyfile
. This is needed for safe handling of files containing either control characters (seescan.go: scan(): case s.chr == '"': ...
for the full list of them) or'
or both in their names.I stumbled upon this when writing a safe lf command like this:
The text was updated successfully, but these errors were encountered: