mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 01:22:28 -05:00 
			
		
		
		
	Noescape (#88)
* disable html escaping for short description * provide noescape function for templates * move template functions before template loading * go fmt * linter fixes
This commit is contained in:
		
					parent
					
						
							
								bdba3ff9a9
							
						
					
				
			
			
				commit
				
					
						f05b255511
					
				
			
		
					 4 changed files with 19 additions and 1 deletions
				
			
		|  | @ -126,6 +126,9 @@ func New(cfg *config.Config, db db.DB, logger *logrus.Logger) (Router, error) { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	// set template functions | ||||||
|  | 	loadTemplateFunctions(engine) | ||||||
|  | 
 | ||||||
| 	// load templates onto the engine | 	// load templates onto the engine | ||||||
| 	if err := loadTemplates(cfg, engine); err != nil { | 	if err := loadTemplates(cfg, engine); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ package router | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"html/template" | ||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 
 | 
 | ||||||
|  | @ -21,3 +22,13 @@ func loadTemplates(cfg *config.Config, engine *gin.Engine) error { | ||||||
| 	engine.LoadHTMLGlob(tmPath) | 	engine.LoadHTMLGlob(tmPath) | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func noescape(str string) template.HTML { | ||||||
|  | 	return template.HTML(str) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func loadTemplateFunctions(engine *gin.Engine) { | ||||||
|  | 	engine.SetFuncMap(template.FuncMap{ | ||||||
|  | 		"noescape": noescape, | ||||||
|  | 	}) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -101,5 +101,9 @@ func (m *Module) Route(s router.Router) error { | ||||||
| 	// 404 handler | 	// 404 handler | ||||||
| 	s.AttachNoRouteHandler(m.NotFoundHandler) | 	s.AttachNoRouteHandler(m.NotFoundHandler) | ||||||
| 
 | 
 | ||||||
|  | 	if err != nil { | ||||||
|  | 		return fmt.Errorf("error setting router FuncMap: %s", err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ | ||||||
| 
 | 
 | ||||||
| 	<h3>This is the default landing page, you can edit it from <span class="accent">./web/template/index.tmpl</span></h1> | 	<h3>This is the default landing page, you can edit it from <span class="accent">./web/template/index.tmpl</span></h1> | ||||||
| 	<p> | 	<p> | ||||||
| 		{{.instance.ShortDescription}} | 		{{.instance.ShortDescription |noescape}} | ||||||
| 	</p> | 	</p> | ||||||
| </section> | </section> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue