mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Fix serving of raw wiki files other than .md (#5814)
* Fix serving of raw wiki files other than .md Closes #4690. Closes #4395. Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Simplify code at routers/repo/wiki.go Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Add more files to user2/repo1.wiki for testing Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Update macaron to v1.3.2 Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Add tests for WikiRaw Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Fix NewResponseWriter usage due to macaron update Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com> * Add raw to reserved wiki names Signed-off-by: Gabriel Silva Simões <simoes.sgabriel@gmail.com>
This commit is contained in:
		
				
					committed by
					
						
						techknowlogick
					
				
			
			
				
	
			
			
			
						parent
						
							4a747aef7b
						
					
				
				
					commit
					3b7f41f9f7
				
			@@ -295,26 +295,41 @@ func WikiRaw(ctx *context.Context) {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	providedPath := ctx.Params("*")
 | 
			
		||||
	if strings.HasSuffix(providedPath, ".md") {
 | 
			
		||||
		providedPath = providedPath[:len(providedPath)-3]
 | 
			
		||||
	}
 | 
			
		||||
	wikiPath := models.WikiNameToFilename(providedPath)
 | 
			
		||||
 | 
			
		||||
	var entry *git.TreeEntry
 | 
			
		||||
	if commit != nil {
 | 
			
		||||
		entry, err = findEntryForFile(commit, wikiPath)
 | 
			
		||||
		// Try to find a file with that name
 | 
			
		||||
		entry, err = findEntryForFile(commit, providedPath)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.ServerError("findFile", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if entry == nil {
 | 
			
		||||
			// Try to find a wiki page with that name
 | 
			
		||||
			if strings.HasSuffix(providedPath, ".md") {
 | 
			
		||||
				providedPath = providedPath[:len(providedPath)-3]
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			wikiPath := models.WikiNameToFilename(providedPath)
 | 
			
		||||
			entry, err = findEntryForFile(commit, wikiPath)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				ctx.ServerError("findFile", err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.ServerError("findFile", err)
 | 
			
		||||
		return
 | 
			
		||||
	} else if entry == nil {
 | 
			
		||||
		ctx.NotFound("findEntryForFile", nil)
 | 
			
		||||
 | 
			
		||||
	if entry != nil {
 | 
			
		||||
		if err = ServeBlob(ctx, entry.Blob()); err != nil {
 | 
			
		||||
			ctx.ServerError("ServeBlob", err)
 | 
			
		||||
		}
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err = ServeBlob(ctx, entry.Blob()); err != nil {
 | 
			
		||||
		ctx.ServerError("ServeBlob", err)
 | 
			
		||||
	}
 | 
			
		||||
	ctx.NotFound("findEntryForFile", nil)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewWiki render wiki create page
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user