From e324f393ea53b3556ce33cf159385f7d11ed3426 Mon Sep 17 00:00:00 2001 From: Robert Kroeger Date: Tue, 11 Feb 2025 09:15:34 +0900 Subject: [PATCH] Support setting names from the filesystem that have spaces With this change, the E command landed earlier will work for files whose names contain spaces as the change permits setting file paths to contain spaces. --- fsys_test.go | 14 ++++++++++---- xfid.go | 19 +++++++++++-------- xfid_test.go | 3 ++- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/fsys_test.go b/fsys_test.go index ee3ec5a3..d7e7a83f 100644 --- a/fsys_test.go +++ b/fsys_test.go @@ -278,7 +278,7 @@ func TestFSys(t *testing.T) { }{ {"/edwood/test1", true}, {"/edwood/世界.txt", true}, - {"/edwood/name with space", false}, + {"/edwood/name with space", true}, {"/edwood/\x00\x00test2", false}, } { err := w.Name(tc.name) @@ -297,9 +297,15 @@ func TestFSys(t *testing.T) { t.Errorf("Failed to read tag: %v\n", err) continue } - tag := strings.SplitN(string(b), " ", 2) - if tc.name != tag[0] { - t.Errorf("Window name is %q; expected %q\n", tag[0], tc.name) + // Supporting spaces requires different parsing. + // TODO(rjk): Consider adding a helper to gozen for this task. + tags := strings.SplitN(string(b), " ", 2) + fn := tags[0] + if b[0] == '\'' { + fn = string(b[1 : bytes.IndexByte(b[1:], '\'')+1]) + } + if tc.name != fn { + t.Errorf("Window name is %q; expected %q\n", fn, tc.name) } } diff --git a/xfid.go b/xfid.go index f6dd24de..b584bb70 100644 --- a/xfid.go +++ b/xfid.go @@ -596,22 +596,25 @@ forloop: err = ErrBadCtl break forloop } - r, _, nulls := util.Cvttorunes([]byte(words[1]), len(words[1])) - if nulls { - err = fmt.Errorf("nulls in file name") - break forloop - } - for _, rr := range r { - if rr <= ' ' { + + fn := words[1] + for _, c := range fn { + if c == '\000' { + err = fmt.Errorf("nulls in file name") + break forloop + } + if c < ' ' { err = fmt.Errorf("bad character in file name") break forloop } } + + // TODO(rjk): There should be some nicer way to do this. if !w.nomark { global.seq++ w.body.file.Mark(global.seq) } - w.SetName(string(r)) + w.SetName(fn) case "dump": // set dump string if len(words) < 2 { err = ErrBadCtl diff --git a/xfid_test.go b/xfid_test.go index 053179da..b4b96ab4 100644 --- a/xfid_test.go +++ b/xfid_test.go @@ -910,7 +910,8 @@ func TestXfidwriteQWctl(t *testing.T) { {ErrBadCtl, "name"}, {nil, "name /Test/Write/Ctl"}, {fmt.Errorf("nulls in file name"), "name /Test/Write\u0000/Ctl"}, - {fmt.Errorf("bad character in file name"), "name /Test/Write To/Ctl"}, + {nil, "name /Test/Write To/Ctl"}, + {fmt.Errorf("bad character in file name"), "name /Test/\037Write To/Ctl"}, {nil, "dump win"}, {ErrBadCtl, "dump"}, {fmt.Errorf("nulls in dump string"), "dump win\u0000rc"},