mirror of https://github.com/gin-gonic/gin.git
Refactor cleanPath switch cases
This commit is contained in:
parent
01ca625b98
commit
32ba640d75
22
path.go
22
path.go
|
@ -48,20 +48,26 @@ func cleanPath(p string) string {
|
||||||
// loop has no expensive function calls (except 1x make)
|
// loop has no expensive function calls (except 1x make)
|
||||||
|
|
||||||
for r < n {
|
for r < n {
|
||||||
switch {
|
switch p[r] {
|
||||||
case p[r] == '/':
|
case '/':
|
||||||
// empty path element, trailing slash is added after the end
|
// empty path element, trailing slash is added after the end
|
||||||
r++
|
r++
|
||||||
|
|
||||||
case p[r] == '.' && r+1 == n:
|
case '.':
|
||||||
|
// . element
|
||||||
|
if r+1 == n {
|
||||||
trailing = true
|
trailing = true
|
||||||
r++
|
r++
|
||||||
|
continue
|
||||||
|
|
||||||
case p[r] == '.' && p[r+1] == '/':
|
} else {
|
||||||
// . element
|
switch p[r+1] {
|
||||||
|
case '/':
|
||||||
r += 2
|
r += 2
|
||||||
|
continue
|
||||||
|
|
||||||
case p[r] == '.' && p[r+1] == '.' && (r+2 == n || p[r+2] == '/'):
|
case '.':
|
||||||
|
if r+2 == n || p[r+2] == '/' {
|
||||||
// .. element: remove to last /
|
// .. element: remove to last /
|
||||||
r += 3
|
r += 3
|
||||||
|
|
||||||
|
@ -79,6 +85,10 @@ func cleanPath(p string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// real path element.
|
// real path element.
|
||||||
|
|
Loading…
Reference in New Issue