Skip to content

Commit

Permalink
fixed path uniformize method
Browse files Browse the repository at this point in the history
  • Loading branch information
RayanMarmar committed May 14, 2024
1 parent 722afce commit 5c2c931
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
13 changes: 2 additions & 11 deletions internal/utils/stringutil/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"path/filepath"
"regexp"
"runtime"
"strings"
)

Expand Down Expand Up @@ -50,17 +49,9 @@ func PathRemoveSpecialCharacter(path string) string {

// PathUniformize returns uniformized path regarding the device OS.
func PathUniformize(path string) string {
// Replace backslashes with forward slashes
// Resolve dots and double slashes

// Handling platform-specific behavior since filepath.Clean behaves differently for each
if runtime.GOOS == "windows" {
path = filepath.ToSlash(path)
}
path = PathRemoveSpecialCharacter(path)
path = filepath.Clean(path)

return path
// Replace backslashes with forward slashes
return filepath.ToSlash(path)
}

// ParseOptions parses a string containing options in various formats
Expand Down
20 changes: 10 additions & 10 deletions internal/utils/stringutil/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ func TestPathUniformize_Success(t *testing.T) {
input string
expected string
}{
{"C:\\path\\to\\file", "C:/path/to/file"},
{"C:\\path\\to\\..\\file", "C:/path/file"},
{"C:\\path\\to\\dir\\..\\file", "C:/path/to/file"},
{"C:\\path\\with\\double\\\\slashes", "C:/path/with/double/slashes"},
{"C:\\path\\with\\dots\\..", "C:/path/with"},
{"C:\\path\\with\\dots\\..\\..", "C:/path"},
{"C:\\path\\with\\dots\\.", "C:/path/with/dots"},
{"C:\\path\\with\\dots\\.\\.", "C:/path/with/dots"},
{"C:\\path\\with\\dots\\.\\.\\..", "C:/path/with"},
{"C:\\path\\with\\dots\\.\\.\\..\\file", "C:/path/with/file"},
{"C:/path/to/file", "C:/path/to/file"},
{"C:/path/to/../file", "C:/path/file"},
{"C:/path/to/dir/../file", "C:/path/to/file"},
{"C:/path/with/double/slashes", "C:/path/with/double/slashes"},
{"C:/path/with/dots/..", "C:/path/with"},
{"C:/path/with/dots/../..", "C:/path"},
{"C:/path/with/dots/.", "C:/path/with/dots"},
{"C:/path/with/dots/./.", "C:/path/with/dots"},
{"C:/path/with/dots/././..", "C:/path/with"},
{"C:/path/with/dots/././../file", "C:/path/with/file"},
}

for _, item := range items {
Expand Down

0 comments on commit 5c2c931

Please sign in to comment.