Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Improve handling of paths containing repeated separators (fix #1946). #1948

Merged
merged 3 commits into from
Jul 23, 2018

Conversation

jpentland
Copy link
Contributor

@jpentland jpentland commented Jul 18, 2018

What does this do / why do we need it?

Issue: #1946

Host system GOPATH may contain repeated separators or other artifacts which can cause an error
when not needed. E.g:

GOPATH:

/home/user//.gopath
/home/user/./.gopath
/home/user/code/../.gopath

Error:

/home/user/.gopath/src/github.com/project/repo is not within a known GOPATH/src

The function filepath.Clean() is used in order to simplify filepaths and remove the artifacts.

What should your reviewer look out for in this PR?

In order to fix the issue only the changes to internal/fs/fs.go are required. However context.go is also
updated to further clean the GOPATH as it gets returned from TestDetectGOPATH.

Test cases were added in context_test.go and internal/fs/fs_test.go, which currently only cover repeated
slashes, since this was what the bugfix is targeting.

There is also one small fix to the test case TestDetectGOPATH where the two string values were reversed in the error statement.

Do you need help or clarification on anything?

I'm not sure if the test case changes should live in separate commits to the actual code fix.

Which issue(s) does this PR fix?

fixes #1649

Error message on unexpected output string parameters were reversed.

Previous error message showed:
"expected GOPATH to be <result>, got <test data>."
…Prefix

Previously strings were being cleaned with strings.TrimSuffix() to remove
trailing separators. However, filepath.Clean() additionally removes
directory navigation symbols (e.g. './', '../') and repeated separators.

TestHasFilepathPrefix has additional test cases added to ensure trailing,
and repeated separators are handled correctly.

Fixes golang#1946
Removes artifacts such as trailing and repeated separators, directory
navigation symbols ('./' '../').

Also add a test case to ensure that repeated separators are handled
correctly (relevant for golang#1946).
@jpentland jpentland requested a review from sdboyer as a code owner July 18, 2018 12:52
@googlebot
Copy link
Collaborator

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

1 similar comment
@googlebot
Copy link
Collaborator

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@jpentland
Copy link
Contributor Author

I signed it!

@googlebot
Copy link
Collaborator

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link
Collaborator

CLAs look good, thanks!

Copy link
Member

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

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

Looks like it should be fine!

Changes to this logic has historically given us some nasty bites, but it really seems like a normalizing function like filepath.Clean() should be safe.

So, as long as the tests pass, best thing to do is just give it a try.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants