Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit ec4f275

Browse files
committed
Fix bug where "/username/" without database name would show an error
1 parent fb59e1b commit ec4f275

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

webui/main.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,10 +3554,12 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
35543554
pathStrings := strings.Split(r.URL.Path, "/")
35553555

35563556
// numPieces will be 2 if the request was for the root directory (https://server/), or if
3557-
// the request included only a single path component (https://server/someuser/)
3557+
// the request included only a single path component (https://server/someuser) and no trailing slash
3558+
var dbName, userName string
35583559
numPieces := len(pathStrings)
3559-
if numPieces == 2 {
3560-
userName := pathStrings[1]
3560+
switch numPieces {
3561+
case 2:
3562+
userName = pathStrings[1]
35613563
// Check if the request was for the root directory
35623564
if pathStrings[1] == "" {
35633565
// Yep, root directory request
@@ -3568,10 +3570,31 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
35683570
// The request was for a user page
35693571
userPage(w, r, userName)
35703572
return
3573+
case 3:
3574+
userName = pathStrings[1]
3575+
dbName = pathStrings[2]
3576+
3577+
// This catches the case where a "/" is on the end of a user page URL
3578+
if dbName == "" {
3579+
// The request was for a user page
3580+
userPage(w, r, userName)
3581+
return
3582+
}
3583+
default:
3584+
// TODO: Add support for folders and sub folders
3585+
// TODO eg: Allow for collections of databases
3586+
// TODO * /user/collectionFoo/database1
3587+
// TODO * /user/collectionFoo/database2
3588+
// TODO * /user/collectionBar/database1
3589+
// TODO * /user/collectionBar/database2
3590+
3591+
// We haven't yet added support for folders and subfolders, so bounce back to the /user/database page
3592+
http.Redirect(w, r, fmt.Sprintf("/%s/%s", pathStrings[1], pathStrings[2]), http.StatusTemporaryRedirect)
3593+
return
35713594
}
35723595

3573-
userName := pathStrings[1]
3574-
dbName := pathStrings[2]
3596+
userName = pathStrings[1]
3597+
dbName = pathStrings[2]
35753598

35763599
// Validate the user supplied user and database name
35773600
err := com.ValidateUserDB(userName, dbName)
@@ -3580,14 +3603,6 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
35803603
return
35813604
}
35823605

3583-
// This catches the case where a "/" is on the end of a user page URL
3584-
// TODO: Refactor this and the above identical code. Doing it this way is non-optimal
3585-
if pathStrings[2] == "" {
3586-
// The request was for a user page
3587-
userPage(w, r, userName)
3588-
return
3589-
}
3590-
35913606
// TODO: Add support for folders and sub-folders in request paths
35923607
dbFolder := "/"
35933608

0 commit comments

Comments
 (0)