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, path/filepath: document that Clean removes trailing slash #3492

Closed
gopherbot opened this issue Apr 7, 2012 · 10 comments
Closed

path, path/filepath: document that Clean removes trailing slash #3492

gopherbot opened this issue Apr 7, 2012 · 10 comments

Comments

@gopherbot
Copy link

by Scheintoter:

What steps will reproduce the problem?
My problem is with the functions path.Clean and filepath.Clean.
They remove a trailing slash at the end of a path.
After reading the documentation I thought it would keep that slash.
Could you please fix the bug or if it is intended that way change the documentation?
Example:
testPath := "/this/is/a/test/"
fmt.Printf("original: %s\n", testPath)
fmt.Printf("cleaned path: %s\n", path.Clean(testPath))
fmt.Printf("cleaned filepath: %s\n", filepath.Clean(testPath))    

full program at:
http://play.golang.org/p/l1L6kGlYLE

What is the expected output?
original: /this/is/a/test/
cleaned path: /this/is/a/test/
cleaned filepath: /this/is/a/test/      (on linux)
cleaned filepath: \this\is\a\test\      (on windows)

What do you see instead?
original: /this/is/a/test/
cleaned path: /this/is/a/test
cleaned filepath: /this/is/a/test      (on play.golang.org)
cleaned filepath: \this\is\a\test      (on my windows computer)


Which compiler are you using (5g, 6g, 8g, gccgo)?
Not sure was is behind the go.exe from the go1 release

Which operating system are you using?
Windows 7 64 bit

Which version are you using?  (run 'go version')
go version go1
@minux
Copy link
Member

minux commented Apr 7, 2012

Comment 1:

why it shouldn't remove the trailing path separator?

@minux
Copy link
Member

minux commented Apr 7, 2012

Comment 2:

why it shouldn't remove the trailing path separator?

@gopherbot
Copy link
Author

Comment 3 by Scheintoter:

Both ways are fine with me, but at http://golang.org/pkg/path/#Clean it isn't mentioned
and I don't want my program to break just because the compiler was made compliant with
the definition.
So I just want to know if I have to expect a change in the definition or a change in the
implementation of the compiler

@robpike
Copy link
Contributor

robpike commented Apr 7, 2012

Comment 4:

If the documentation is unclear should be updated. The returned path will be as clean as
it can be.

Labels changed: added priority-soon, documentation, removed priority-triage.

Owner changed to @robpike.

Status changed to Accepted.

@gopherbot
Copy link
Author

Comment 5 by jo@durchholz.org:

The trailing slash should be removed.
That way, the cleaned path will work not just for directories but for files as well.
The main description is clear ("shortest equivalent"), but the detail explanation on
http://golang.org/pkg/path/filepath/#Clean shoud list trailing slash removal as fifth
point.

@rsc
Copy link
Contributor

rsc commented Apr 10, 2012

Comment 6:

Note that Clean does not remove the trailing slash in "/".
I am not sure what it does for `C:\` on Windows, but I
suspect it leaves the trailing slash there too.

Labels changed: added go1.1.

@gopherbot
Copy link
Author

Comment 7 by Scheintoter:

I don't think removing the trailing slash keeps the path equivalent.
"/this/is/a/"+"test.txt"
is something else than
path.Clean("/this/is/a/")+"test.txt"

@rsc
Copy link
Contributor

rsc commented Apr 17, 2012

Comment 8:

path.Clean("/this/is/..")+"test.txt" changes too.
That's not something we promise.

@robpike
Copy link
Contributor

robpike commented Apr 24, 2012

Comment 9:

This issue was closed by revision 5fc2af1.

Status changed to Fixed.

@robpike
Copy link
Contributor

robpike commented Apr 25, 2012

Comment 10:

This issue was closed by revision 017c74115061.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
robpike added a commit that referenced this issue May 11, 2015
««« backport ab273014412e
path: document that Clean deletes trailing slashes.

Fixes #3492.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6112044
»»»
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc unassigned robpike Jun 22, 2022
This issue was closed.
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