Fix go-fuzz (#15596)
* Fix go-fuzz followup of https://github.com/go-gitea/gitea/pull/15175 * simplify * enhance
This commit is contained in:
		
							parent
							
								
									e91932bc15
								
							
						
					
					
						commit
						bee8ce342f
					
				
					 1 changed files with 22 additions and 10 deletions
				
			
		|  | @ -7,6 +7,9 @@ | ||||||
| package fuzz | package fuzz | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"bytes" | ||||||
|  | 	"io" | ||||||
|  | 
 | ||||||
| 	"code.gitea.io/gitea/modules/markup" | 	"code.gitea.io/gitea/modules/markup" | ||||||
| 	"code.gitea.io/gitea/modules/markup/markdown" | 	"code.gitea.io/gitea/modules/markup/markdown" | ||||||
| ) | ) | ||||||
|  | @ -18,17 +21,26 @@ import ( | ||||||
| // (for example, the input is lexically correct and was parsed successfully).
 | // (for example, the input is lexically correct and was parsed successfully).
 | ||||||
| // -1 if the input must not be added to corpus even if gives new coverage and 0 otherwise.
 | // -1 if the input must not be added to corpus even if gives new coverage and 0 otherwise.
 | ||||||
| 
 | 
 | ||||||
| func FuzzMarkdownRenderRaw(data []byte) int { | var ( | ||||||
| 	_ = markdown.RenderRaw(data, "", false) | 	renderContext = markup.RenderContext{ | ||||||
| 	return 1 | 		URLPrefix: "https://example.com", | ||||||
| } | 		Metas: map[string]string{ | ||||||
| 
 | 			"user": "go-gitea", | ||||||
| func FuzzMarkupPostProcess(data []byte) int { | 			"repo": "gitea", | ||||||
| 	var localMetas = map[string]string{ | 		}, | ||||||
| 		"user": "go-gitea", |  | ||||||
| 		"repo": "gitea", |  | ||||||
| 	} | 	} | ||||||
| 	_, err := markup.PostProcess(data, "https://example.com", localMetas, false) | ) | ||||||
|  | 
 | ||||||
|  | func FuzzMarkdownRenderRaw(data []byte) int { | ||||||
|  | 	err := markdown.RenderRaw(&renderContext, bytes.NewReader(data), io.Discard) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return 0 | ||||||
|  | 	} | ||||||
|  | 	return 1 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func FuzzMarkupPostProcess(data []byte) int { | ||||||
|  | 	err := markup.PostProcess(&renderContext, bytes.NewReader(data), io.Discard) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return 0 | 		return 0 | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue