trzsz / trzsz-go

trzsz-go is the go version of trzsz, makes all terminals that support local shell to support trzsz ( trz / tsz ).
https://trzsz.github.io/go
MIT License
878 stars 53 forks source link

seems dragfile can't handle filename contains ' or space ? #57

Open yurenchen000 opened 1 week ago

yurenchen000 commented 1 week ago

on linux, if a file path is /tmp/12' 3' it seems not safe to encode/decode with current scheme?

https://github.com/trzsz/trzsz-go/blob/5622a20/trzsz/drag.go#L73 //I noticed the drag detect logic when I try to adapting to a vte-based terminal (terminator or gnome-terminal)

lonnywong commented 1 week ago

On Linux, if the path contains spaces, the dragged path will be similar to '/tmp/12 3'

yurenchen000 commented 1 week ago

On Linux, if the path contains spaces, the dragged path will be similar to '/tmp/12 3'

if the file is /tmp/12' 3 (contains both space and ') current parser may not work

lonnywong commented 1 week ago

Which Linux and Terminal would be like this? We only deal with real issues, not imaginary ones.

yurenchen000 commented 1 week ago

it's


trzsz_drag_warp1-


test files (one file at a time):

lonnywong commented 1 week ago

Maybe https://github.com/google/shlex can support it.

yurenchen000 commented 1 week ago

Maybe https://github.com/google/shlex can support it.

Agree. I think it follows shell quoting when drag files to warp terminal (only tested with warp 0.2024.09.10.08.02.stable, ubuntu 22)

shlex.Split() do it well


Test code:

// string got from warp terminal when drag files
str := `/run/test/temp/22\ 3 /run/test/temp/32\ 3\' /run/test/temp/123`

// try to split and decode it
arr, err := shlex.Split(str)

fmt.Println("s1:", str)
fmt.Printf("ss: %#v\n", arr)

Result is as expected.

s1: /run/test/temp/22\ 3 /run/test/temp/32\ 3\' /run/test/temp/123
ss: []string{"/run/test/temp/22 3", "/run/test/temp/32 3'", "/run/test/temp/123"}