fix(wiki): check directory before file lookup to prevent raw redirect
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 1s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Generic: Repo Health / Access control (pull_request) Successful in 2s
PR RC Release / Build RC Release (pull_request) Successful in 2s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Branch Cleanup / Delete merged branch (pull_request) Successful in 2s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || 'development' }}) (pull_request) Successful in 1m0s
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 1s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Generic: Repo Health / Access control (pull_request) Successful in 2s
PR RC Release / Build RC Release (pull_request) Successful in 2s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Branch Cleanup / Delete merged branch (pull_request) Successful in 2s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || 'development' }}) (pull_request) Successful in 1m0s
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report Issues (pull_request) Has been cancelled
Directory paths were being found by wikiEntryByName as non-.md entries, triggering a redirect to /wiki/raw/. Now checks for directories first and handles index file lookup before the file/raw detection.
This commit is contained in:
+30
-29
@@ -254,38 +254,39 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
|
||||
wikiTree := buildWikiTree(commit)
|
||||
ctx.Data["WikiTree"] = wikiTree
|
||||
|
||||
// Check if path is a directory first (before file lookup)
|
||||
dirEntry, _ := commit.GetTreeEntryByPath(string(pageName))
|
||||
if dirEntry != nil && dirEntry.IsDir() {
|
||||
// Path is a directory - try index files or show folder listing
|
||||
var entry *git.TreeEntry
|
||||
foundIndex := false
|
||||
for _, indexName := range []string{"README", "Home", "index"} {
|
||||
indexPath := wiki_service.WebPath(string(pageName) + "/" + indexName)
|
||||
idxEntry, _, idxNoEntry, _ := wikiEntryByName(ctx, commit, indexPath)
|
||||
if !idxNoEntry && idxEntry != nil {
|
||||
pageName = indexPath
|
||||
entry = idxEntry
|
||||
_, displayName = wiki_service.WebPathToUserTitle(pageName)
|
||||
ctx.Data["PageURL"] = wiki_service.WebPathToURLPath(pageName)
|
||||
ctx.Data["Title"] = displayName
|
||||
foundIndex = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundIndex {
|
||||
ctx.Data["IsWikiFolder"] = true
|
||||
ctx.Data["WikiFolderPath"] = string(pageName)
|
||||
folderEntries := listWikiFolderEntries(commit, string(pageName))
|
||||
ctx.Data["WikiFolderEntries"] = folderEntries
|
||||
return wikiGitRepo, nil
|
||||
}
|
||||
_ = entry // will be used below via pageName lookup
|
||||
}
|
||||
|
||||
// lookup filename in wiki - get gitTree entry , real filename
|
||||
entry, pageFilename, noEntry, isRaw := wikiEntryByName(ctx, commit, pageName)
|
||||
if noEntry {
|
||||
// Check if path is a directory - try index files or show folder listing
|
||||
dirEntry, _ := commit.GetTreeEntryByPath(string(pageName))
|
||||
if dirEntry != nil && dirEntry.IsDir() {
|
||||
// Try index files: README.md, Home.md, index.md
|
||||
for _, indexName := range []string{"README", "Home", "index"} {
|
||||
indexPath := wiki_service.WebPath(string(pageName) + "/" + indexName)
|
||||
idxEntry, _, idxNoEntry, _ := wikiEntryByName(ctx, commit, indexPath)
|
||||
if !idxNoEntry && idxEntry != nil {
|
||||
// Found index file - render it
|
||||
pageName = indexPath
|
||||
entry = idxEntry
|
||||
_, displayName = wiki_service.WebPathToUserTitle(pageName)
|
||||
ctx.Data["PageURL"] = wiki_service.WebPathToURLPath(pageName)
|
||||
ctx.Data["Title"] = displayName
|
||||
noEntry = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if noEntry {
|
||||
// No index file - show folder listing
|
||||
ctx.Data["IsWikiFolder"] = true
|
||||
ctx.Data["WikiFolderPath"] = string(pageName)
|
||||
folderEntries := listWikiFolderEntries(commit, string(pageName))
|
||||
ctx.Data["WikiFolderEntries"] = folderEntries
|
||||
return wikiGitRepo, nil
|
||||
}
|
||||
} else {
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages")
|
||||
}
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages")
|
||||
}
|
||||
if isRaw {
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/raw/" + string(pageName))
|
||||
|
||||
Reference in New Issue
Block a user