Minor cleanup and fixes

- Do not allow '.' as path component, because it undermines depth
  checks, and add tests
- Fix GiB reporting
- Fix metrics label
- Helper function for http errors
This commit is contained in:
Konrad Wojas 2020-05-31 21:36:39 +08:00 committed by Alexander Neumann
parent 1f593fafaf
commit d4cd47e503
5 changed files with 41 additions and 18 deletions

View file

@ -165,14 +165,14 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// getObject parses the URL path and returns the objectType and objectID,
// if any. The objectID is optional.
func (h *Handler) getObject(urlPath string) (objectType, objectID string) {
if m := BlobPathRE.FindStringSubmatch(urlPath); len(m) > 0 {
if len(m) == 2 || m[2] == "" {
return m[1], ""
}
return m[1], m[2]
} else {
return "", ""
m := BlobPathRE.FindStringSubmatch(urlPath)
if len(m) == 0 {
return "", "" // no match
}
if len(m) == 2 || m[2] == "" {
return m[1], "" // no objectID
}
return m[1], m[2]
}
// getSubPath returns the path for a file or subdir in the root of the repo.