Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
galene
Commits
8f89ac0b
Commit
8f89ac0b
authored
Feb 07, 2021
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up path handling in webserver.
parent
c4e26b65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
9 deletions
+43
-9
webserver/webserver.go
webserver/webserver.go
+12
-9
webserver/webserver_test.go
webserver/webserver_test.go
+31
-0
No files found.
webserver/webserver.go
View file @
8f89ac0b
...
...
@@ -242,20 +242,23 @@ func serveFile(w http.ResponseWriter, r *http.Request, p string) {
http
.
ServeContent
(
w
,
r
,
fi
.
Name
(),
fi
.
ModTime
(),
f
)
}
func
parseGroupName
(
p
ath
string
)
string
{
if
!
strings
.
HasPrefix
(
p
ath
,
"/group/"
)
{
func
parseGroupName
(
p
refix
string
,
p
string
)
string
{
if
!
strings
.
HasPrefix
(
p
,
prefix
)
{
return
""
}
name
:=
p
ath
[
len
(
"/group/"
)
:
]
name
:=
p
[
len
(
"/group/"
)
:
]
if
name
==
""
{
return
""
}
if
name
[
len
(
name
)
-
1
]
==
'/'
{
name
=
name
[
:
len
(
name
)
-
1
]
if
filepath
.
Separator
!=
'/'
&&
strings
.
ContainsRune
(
name
,
filepath
.
Separator
)
{
return
""
}
return
name
name
=
path
.
Clean
(
"/"
+
name
)
return
name
[
1
:
]
}
func
groupHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -264,14 +267,14 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
}
mungeHeader
(
w
)
name
:=
parseGroupName
(
r
.
URL
.
Path
)
name
:=
parseGroupName
(
"/group/"
,
r
.
URL
.
Path
)
if
name
==
""
{
notFound
(
w
)
return
}
if
strings
.
HasSuffix
(
r
.
URL
.
Path
,
"/"
)
{
http
.
Redirect
(
w
,
r
,
r
.
URL
.
Path
[
:
len
(
r
.
URL
.
Path
)
-
1
]
,
if
r
.
URL
.
Path
!=
"/group/"
+
name
{
http
.
Redirect
(
w
,
r
,
"/group/"
+
name
,
http
.
StatusPermanentRedirect
)
return
}
...
...
webserver/webserver_test.go
0 → 100644
View file @
8f89ac0b
package
webserver
import
(
"testing"
)
func
TestParseGroupName
(
t
*
testing
.
T
)
{
a
:=
[]
struct
{
p
,
g
string
}{
{
""
,
""
},
{
"/foo"
,
""
},
{
"foo"
,
""
},
{
"group/foo"
,
""
},
{
"/group"
,
""
},
{
"/group/.."
,
""
},
{
"/group/foo/../bar"
,
"bar"
},
{
"/group/foo"
,
"foo"
},
{
"/group/foo/"
,
"foo"
},
{
"/group/foo/bar"
,
"foo/bar"
},
{
"/group/foo/bar/"
,
"foo/bar"
},
}
for
_
,
pg
:=
range
a
{
t
.
Run
(
pg
.
p
,
func
(
t
*
testing
.
T
)
{
g
:=
parseGroupName
(
"/group/"
,
pg
.
p
)
if
g
!=
pg
.
g
{
t
.
Errorf
(
"Path %v, got %v, expected %v"
,
pg
.
p
,
g
,
pg
.
g
)
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment