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

Correctly normalize Windows package paths. #392

Merged
merged 6 commits into from
Apr 26, 2016
Merged
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
1 change: 1 addition & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func NormalizeName(name string) (string, string) {
}
}

name = filepath.ToSlash(name)
root := GetRootFromPackage(name)
Copy link
Member

Choose a reason for hiding this comment

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

What do we get from this? The first thing GetRootFromPackage does is run filepath.ToSlash. GetRootFromPackage is sometimes called outside NormalizeName.

Is there a problem in the latest code that needs to be addressed?

Copy link
Contributor Author

@jrick jrick Apr 22, 2016

Choose a reason for hiding this comment

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

The issue is that name contains backslashes. The root is normalized, but the full name is not, so the prefix trim doesn't work as intended.

With github.com\foo\bar\baz as input:

// name == "github.com\foo\bar\baz"
root := GetRootFromPackage(name) // root == "github.com/foo/bar"
extra := strings.TrimPrefix(name, root) // extra == "github.com\foo\bar\baz"

Copy link
Member

Choose a reason for hiding this comment

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

I see the bug I introduced now.

extra := strings.TrimPrefix(name, root)
if len(extra) > 0 && extra != "/" {
Expand Down