File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -22,9 +22,10 @@ import (
2222// See:
2323// - https://pubs.opengroup.org/onlinepubs/9799919799/utilities/basename.html
2424func CleanFileName (path string ) string {
25- if i := strings .LastIndexByte (path , '/' ); i < 0 {
26- return path
27- } else if path = path [i + 1 :]; path != "." && path != ".." {
25+ if i := strings .LastIndexByte (path , '/' ); i >= 0 {
26+ path = path [i + 1 :]
27+ }
28+ if path != "." && path != ".." {
2829 return path
2930 }
3031 return ""
Original file line number Diff line number Diff line change @@ -25,12 +25,17 @@ func TestCleanFileName(t *testing.T) {
2525 })
2626
2727 t .Run ("Dots" , func (t * testing.T ) {
28+ assert .Equal (t , CleanFileName ("." ), "" )
29+ assert .Equal (t , CleanFileName (".." ), "" )
30+ assert .Equal (t , CleanFileName ("..." ), "..." )
31+ assert .Equal (t , CleanFileName ("././/.././../." ), "" )
2832 assert .Equal (t , CleanFileName ("././/.././../.." ), "" )
2933 assert .Equal (t , CleanFileName ("././/.././../../x.j" ), "x.j" )
3034 })
3135
3236 t .Run ("Directories" , func (t * testing.T ) {
3337 assert .Equal (t , CleanFileName ("/" ), "" )
38+ assert .Equal (t , CleanFileName ("//" ), "" )
3439 assert .Equal (t , CleanFileName ("asdf/" ), "" )
3540 assert .Equal (t , CleanFileName ("asdf//12.3" ), "12.3" )
3641 assert .Equal (t , CleanFileName ("//////" ), "" )
You can’t perform that action at this time.
0 commit comments