Skip to content

Commit

Permalink
Support setting names from the filesystem that have spaces
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjkroege committed Feb 11, 2025
1 parent 13c1cd3 commit a346989
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
14 changes: 10 additions & 4 deletions fsys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,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)
Expand All @@ -298,9 +298,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)
}
}

Expand Down
19 changes: 11 additions & 8 deletions xfid.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,22 +597,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
Expand Down
3 changes: 2 additions & 1 deletion xfid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,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"},
Expand Down

0 comments on commit a346989

Please sign in to comment.