File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -72,8 +72,10 @@ func isSlash(c rune) bool {
7272}
7373
7474func getPathEntries (path string , tailSlash bool ) []pathEntry {
75- paths := []string {"/" }
76- paths = append (paths , strings .FieldsFunc (path , isSlash )... )
75+ restPaths := strings .FieldsFunc (path , isSlash )
76+ paths := make ([]string , 1 , len (restPaths )+ 1 )
77+ paths [0 ] = "/"
78+ paths = append (paths , restPaths ... )
7779
7880 displayPathsCount := len (paths )
7981
Original file line number Diff line number Diff line change 1+ package serverHandler
2+
3+ import "testing"
4+
5+ func TestGetPathEntries (t * testing.T ) {
6+ var result []pathEntry
7+
8+ result = getPathEntries ("/a/b/c" , false )
9+ if len (result ) != 4 {
10+ t .Error (len (result ))
11+ }
12+ if result [0 ].Path != "../../" || result [0 ].Name != "/" {
13+ t .Error (result [0 ])
14+ }
15+ if result [1 ].Path != "../" || result [1 ].Name != "a" {
16+ t .Error (result [1 ])
17+ }
18+ if result [2 ].Path != "./" || result [2 ].Name != "b" {
19+ t .Error (result [2 ])
20+ }
21+ if result [3 ].Path != "./c/" || result [3 ].Name != "c" {
22+ t .Error (result [3 ])
23+ }
24+
25+ result = getPathEntries ("/a/b/c" , true )
26+ if len (result ) != 4 {
27+ t .Error (len (result ))
28+ }
29+ if result [0 ].Path != "../../../" || result [0 ].Name != "/" {
30+ t .Error (result [0 ])
31+ }
32+ if result [1 ].Path != "../../" || result [1 ].Name != "a" {
33+ t .Error (result [1 ])
34+ }
35+ if result [2 ].Path != "../" || result [2 ].Name != "b" {
36+ t .Error (result [2 ])
37+ }
38+ if result [3 ].Path != "./" || result [3 ].Name != "c" {
39+ t .Error (result [3 ])
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments