Skip to content

Commit

Permalink
fixed call to filepath.Clean() in archives.Set()
Browse files Browse the repository at this point in the history
this fixes an issue on Windows where ROM selector could
not navigate backwards out of the installation folder.
Issue #30
  • Loading branch information
JetSetIlly committed Jun 14, 2024
1 parent e97629f commit 166a88c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions archivefs/archivefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package archivefs_test
import (
"fmt"
"io"
"os"
"path/filepath"
"testing"

Expand All @@ -31,6 +32,13 @@ func TestArchivefsPath(t *testing.T) {
var entries []archivefs.Entry
var err error

// get working directory for test. we need this so we can modify the testing
// path for comparison with result from the archivefs.Set() function
wd, err := os.Getwd()
test.ExpectSuccess(t, err)
wd, err = filepath.Abs(wd)
test.ExpectSuccess(t, err)

// non-existant file
path = "foo"
err = afs.Set(path, false)
Expand All @@ -41,7 +49,7 @@ func TestArchivefsPath(t *testing.T) {
path = "testdir"
err = afs.Set(path, false)
test.ExpectSuccess(t, err)
test.ExpectEquality(t, afs.String(), path)
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
test.ExpectSuccess(t, afs.IsDir())
test.ExpectSuccess(t, !afs.InArchive())

Expand All @@ -61,7 +69,7 @@ func TestArchivefsPath(t *testing.T) {
path = filepath.Join("testdir", "testfile")
err = afs.Set(path, false)
test.ExpectSuccess(t, err)
test.ExpectEquality(t, afs.String(), path)
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
test.ExpectSuccess(t, !afs.IsDir())
test.ExpectSuccess(t, !afs.InArchive())

Expand All @@ -76,7 +84,7 @@ func TestArchivefsPath(t *testing.T) {
path = filepath.Join("testdir", "testarchive.zip")
err = afs.Set(path, false)
test.ExpectSuccess(t, err)
test.ExpectEquality(t, afs.String(), path)
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
test.ExpectSuccess(t, afs.IsDir())
test.ExpectSuccess(t, afs.InArchive())

Expand All @@ -90,15 +98,15 @@ func TestArchivefsPath(t *testing.T) {
path = filepath.Join("testdir", "testarchive.zip", "archivefile1")
err = afs.Set(path, false)
test.ExpectSuccess(t, err)
test.ExpectEquality(t, afs.String(), path)
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
test.ExpectSuccess(t, !afs.IsDir())
test.ExpectSuccess(t, afs.InArchive())

// directory a real archive
path = filepath.Join("testdir", "testarchive.zip", "archivedir")
err = afs.Set(path, false)
test.ExpectSuccess(t, err)
test.ExpectEquality(t, afs.String(), path)
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
test.ExpectSuccess(t, afs.IsDir())
test.ExpectSuccess(t, afs.InArchive())

Expand All @@ -112,7 +120,7 @@ func TestArchivefsPath(t *testing.T) {
path = filepath.Join("testdir", "testarchive.zip", "archivedir", "archivefile3")
err = afs.Set(path, false)
test.ExpectSuccess(t, err)
test.ExpectEquality(t, afs.String(), path)
test.ExpectEquality(t, afs.String(), filepath.Join(wd, path))
test.ExpectSuccess(t, !afs.IsDir())
test.ExpectSuccess(t, afs.InArchive())
}
Expand Down
2 changes: 1 addition & 1 deletion archivefs/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (afs *Path) Set(path string, fallback bool) error {
}

// make sure path is clean
afs.current = filepath.Clean(search)
afs.current = filepath.Clean(afs.current)

return nil
}

0 comments on commit 166a88c

Please sign in to comment.