diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 32f5413..c3c5607 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,8 +5,11 @@ on: jobs: build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ macos-latest, windows-latest, ubuntu-latest ] name: build and test - runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/cleanse.go b/cleanse.go index 0d828a9..49fed61 100644 --- a/cleanse.go +++ b/cleanse.go @@ -1,10 +1,23 @@ package memoryfs import ( - "path/filepath" "strings" ) func cleanse(path string) string { - return strings.TrimPrefix(strings.TrimPrefix(filepath.Clean(path), "."), separator) + path = strings.TrimPrefix(path, separator) + var accepted []string + for _, part := range strings.Split(path, separator) { + switch { + case part == "" || part == ".": + continue + case part == "..": + if len(accepted) > 0 { + accepted = accepted[:len(accepted)-1] + } + continue + } + accepted = append(accepted, part) + } + return strings.Join(accepted, separator) }