Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions cleanse.go
Original file line number Diff line number Diff line change
@@ -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)
}