Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: broken normalisePath/normalisePathWin on windows #1134

Open
wants to merge 3 commits into
base: gh-windows
Choose a base branch
from
Open
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion internal/transformations/normalise_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import (
"path/filepath"
"strings"
)

func normalisePath(data string) (string, bool, error) {
Expand All @@ -13,10 +14,15 @@
return data, false, nil
}
clean := filepath.Clean(data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same approach as in #1135 (review) for a Clean function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said in the other issue, the compiler optimizes the if away. Using build tags and seperate files would make this far more complicated.

if filepath.Separator != '/' {
// filepath.Clean uses filepath.Separator for the cleaned path
// on windows we need to replace the Separator with the expected forward slash
clean = strings.ReplaceAll(clean, string(filepath.Separator), "/")

Check warning on line 20 in internal/transformations/normalise_path.go

View check run for this annotation

Codecov / codecov/patch

internal/transformations/normalise_path.go#L20

Added line #L20 was not covered by tests
}
if clean == "." {
return "", true, nil
}
if data[len(data)-1] == '/' {
if data[len(data)-1] == '/' || data[len(data)-1] == '\\' {
fzipi marked this conversation as resolved.
Show resolved Hide resolved
return clean + "/", true, nil
}
return clean, data != clean, nil
Expand Down
Loading