mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Use multi reader instead to concat strings (#22099)
extract from #20326
This commit is contained in:
		@@ -305,18 +305,15 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
 | 
				
			|||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res := bytes.NewBuffer(make([]byte, 0, len(rawHTML)+50))
 | 
					 | 
				
			||||||
	// prepend "<html><body>"
 | 
					 | 
				
			||||||
	_, _ = res.WriteString("<html><body>")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Strip out nuls - they're always invalid
 | 
					 | 
				
			||||||
	_, _ = res.Write(tagCleaner.ReplaceAll([]byte(nulCleaner.Replace(string(rawHTML))), []byte("<$1")))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// close the tags
 | 
					 | 
				
			||||||
	_, _ = res.WriteString("</body></html>")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// parse the HTML
 | 
						// parse the HTML
 | 
				
			||||||
	node, err := html.Parse(res)
 | 
						node, err := html.Parse(io.MultiReader(
 | 
				
			||||||
 | 
							// prepend "<html><body>"
 | 
				
			||||||
 | 
							strings.NewReader("<html><body>"),
 | 
				
			||||||
 | 
							// Strip out nuls - they're always invalid
 | 
				
			||||||
 | 
							bytes.NewReader(tagCleaner.ReplaceAll([]byte(nulCleaner.Replace(string(rawHTML))), []byte("<$1"))),
 | 
				
			||||||
 | 
							// close the tags
 | 
				
			||||||
 | 
							strings.NewReader("</body></html>"),
 | 
				
			||||||
 | 
						))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return &postProcessError{"invalid HTML", err}
 | 
							return &postProcessError{"invalid HTML", err}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user