-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: Dir() returns incorrect result if the path contains a trailing slash #13199
Comments
There does seem to be an inconsistency between |
CL https://golang.org/cl/16791 mentions this issue. |
The docs for Dir say "Dir returns all but the last element of path, typically the path's directory." They don't guarantee to get the path's directory. See my longer comment on CL 16791, but I don't think we should change this. |
This was specifically regarding the oddity in the current implementation (the second case in the playground link above):
Whether filepath.Clean(p) == filepath.Join(filepath.Dir(p), filepath.Base(p)) |
@0xmohit that's not guaranteed by the docs. The docs state different behaviors for Dir and Base, and I don't feel at liberty to contradict the established behavior and docs. If you need that guarantee, use filepath.Split. |
filepath.Dir returns incorrect result if the specified path contains a trailing slash. For example, if the input were
/home/
, thenfilepath.Dir
andfilepath.Base
return/home
andhome
respectively. Playground link.Following is the output of
dirname
andbasename
from GNU coreutils:When the input doesn't contain a trailing slash, then the functions yield expected output.
The text was updated successfully, but these errors were encountered: