mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-22 10:39:41 +08:00
Refactor flash message and remove SanitizeHTML template func (#37179)
1. Fix the "flash message" layout problem for different cases * I am sure most of the users should have ever seen the ugly center-aligned error message with multiple lines. 2. Fix inconsistent "Details" flash message EOL handling, sometimes `\n`, sometimes `<br>` * Now, always use "\n" and use `<pre>` to render 3. Remove SanitizeHTML template func because it is not useful and can be easily abused. * But it is still kept for mail templates, for example: https://github.com/go-gitea/gitea/issues/36049 4. Clarify PostProcessCommitMessage's behavior and add FIXME comment By the way: cleaned up some devtest pages, move embedded style block to CSS file
This commit is contained in:
@@ -45,8 +45,8 @@ func List(ctx *context.Context) {
|
||||
|
||||
func FetchActionTest(ctx *context.Context) {
|
||||
_ = ctx.Req.ParseForm()
|
||||
ctx.Flash.Info("fetch-action: " + ctx.Req.Method + " " + ctx.Req.RequestURI + "<br>" +
|
||||
"Form: " + ctx.Req.Form.Encode() + "<br>" +
|
||||
ctx.Flash.Info("fetch-action: " + ctx.Req.Method + " " + ctx.Req.RequestURI + "\n" +
|
||||
"Form: " + ctx.Req.Form.Encode() + "\n" +
|
||||
"PostForm: " + ctx.Req.PostForm.Encode(),
|
||||
)
|
||||
time.Sleep(2 * time.Second)
|
||||
@@ -192,11 +192,31 @@ func prepareMockData(ctx *context.Context) {
|
||||
prepareMockDataBadgeActionsSvg(ctx)
|
||||
case "/devtest/relative-time":
|
||||
prepareMockDataRelativeTime(ctx)
|
||||
case "/devtest/toast-and-message":
|
||||
prepareMockDataToastAndMessage(ctx)
|
||||
case "/devtest/unicode-escape":
|
||||
prepareMockDataUnicodeEscape(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func prepareMockDataToastAndMessage(ctx *context.Context) {
|
||||
msgWithDetails, _ := ctx.RenderToHTML("base/alert_details", map[string]any{
|
||||
"Message": "message with details <script>escape xss</script>",
|
||||
"Summary": "summary with details",
|
||||
"Details": "details line 1\n details line 2\n details line 3",
|
||||
})
|
||||
msgWithSummary, _ := ctx.RenderToHTML("base/alert_details", map[string]any{
|
||||
"Message": "message with summary <script>escape xss</script>",
|
||||
"Summary": "summary only",
|
||||
})
|
||||
|
||||
ctx.Flash.ErrorMsg = string(msgWithDetails)
|
||||
ctx.Flash.WarningMsg = string(msgWithSummary)
|
||||
ctx.Flash.InfoMsg = "a long message with line break\nthe second line <script>removed xss</script>"
|
||||
ctx.Flash.SuccessMsg = "single line message <script>removed xss</script>"
|
||||
ctx.Data["Flash"] = ctx.Flash
|
||||
}
|
||||
|
||||
func prepareMockDataUnicodeEscape(ctx *context.Context) {
|
||||
content := "// demo code\n"
|
||||
content += "if accessLevel != \"user\u202E \u2066// Check if admin (invisible char)\u2069 \u2066\" { }\n"
|
||||
@@ -223,8 +243,8 @@ func TmplCommon(ctx *context.Context) {
|
||||
prepareMockData(ctx)
|
||||
if ctx.Req.Method == http.MethodPost {
|
||||
_ = ctx.Req.ParseForm()
|
||||
ctx.Flash.Info("form: "+ctx.Req.Method+" "+ctx.Req.RequestURI+"<br>"+
|
||||
"Form: "+ctx.Req.Form.Encode()+"<br>"+
|
||||
ctx.Flash.Info("form: "+ctx.Req.Method+" "+ctx.Req.RequestURI+"\n"+
|
||||
"Form: "+ctx.Req.Form.Encode()+"\n"+
|
||||
"PostForm: "+ctx.Req.PostForm.Encode(),
|
||||
true,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user