improve pathBuilder commenting, reduce repeated code

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
development
kim (grufwub) 3 years ago
parent f7e43d4d10
commit 1d05e31dfb

@ -263,7 +263,8 @@ func sanitizePath(raw string) string {
// If next char is '.'
if raw[index] == '.' {
// Hit end of the path, break-out
// Hit end of the path on a '..',
// backtrack and break-out
if index+1 == length {
pb.backtrack()
break
@ -273,7 +274,8 @@ func sanitizePath(raw string) string {
index++
// If next char is '/' then this is a
// back-track segment.
// backtrack segment, backtrack and skip
// to next
if raw[index] == '/' {
pb.backtrack()
continue
@ -282,29 +284,21 @@ func sanitizePath(raw string) string {
// Split for next segment
pb.split()
// Else, add a '.'
// '..' but no backtrack, add to path
// (next '.' is added below)
pb.append('.')
} else {
// Split for next segment
pb.split()
}
// Else, append a '.'
// '.' but no backtrack, add to path
pb.append('.')
// Continue adding up to next '/'
for ; index < length && raw[index] != '/'; index++ {
pb.append(raw[index])
}
// Final iter to skip past the final '/'
index++
continue
} else {
// Split for next segment
pb.split()
}
// Split for next segment
pb.split()
// Iter through and add up to next '/'
for ; index < length && raw[index] != '/'; index++ {
pb.append(raw[index])

Loading…
Cancel
Save