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

path/filepath: HasPrefix should be marked deprecated #18355

Closed
dsnet opened this issue Dec 16, 2016 · 6 comments
Closed

path/filepath: HasPrefix should be marked deprecated #18355

dsnet opened this issue Dec 16, 2016 · 6 comments

Comments

@dsnet
Copy link
Member

dsnet commented Dec 16, 2016

The documentation for filepath.HasPrefix says:

HasPrefix exists for historical compatibility and should not be used.

We should switch this to use the "Deprecated:" tag so that tools can flag new uses of this.

As it is currently implemented, it is misleading because it only does strings.HasPrefix and does not actually match on patch segments. Thus, the following reports true, which is surprising:

filepath.HasPrefix("/home/userwrongdir/abc", "/home/user") // This reports true

\cc @neild

@dsnet dsnet added this to the Go1.9 milestone Dec 16, 2016
@bradfitz
Copy link
Contributor

Just send it now for Go 1.8. It's only docs.

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/34554 mentions this issue.

@dsnet
Copy link
Member Author

dsnet commented Dec 16, 2016

Opened #18358 to investigate actually fixing this function.

@RobbieMcKinstry
Copy link

Just checking: this function is deprecated, and there is no alternative? Maybe a regex.Match? I assume that's why there's interest in fixing.

@bradfitz
Copy link
Contributor

bradfitz commented May 2, 2017

@RobbieMcKinstry, your comment would be better on an open bug, like #18358. Closed bugs aren't tracked.

@RobbieMcKinstry
Copy link

Thank you Brad! Still learning! :)

@golang golang locked and limited conversation to collaborators May 2, 2018
@rsc rsc unassigned dsnet Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants