mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 12:59:11 -05:00
16879b07d2
Related to #2773 Related to Refactor URL detection [gitea#29960](https://github.com/go-gitea/gitea/pull/29960) Related to Refactor external URL detection [gitea#29973](https://github.com/go-gitea/gitea/pull/29973) I added a bunch of tests to `httplib.TestIsRiskyRedirectURL` and some cases should be better handled (however it is not an easy task). I also ported the removal of `utils.IsExternalURL`, since it prevents duplicated (subtle) code. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3167 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: oliverpool <git@olivier.pfad.fr> Co-committed-by: oliverpool <git@olivier.pfad.fr>
40 lines
766 B
Go
40 lines
766 B
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package utils
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestSanitizeFlashErrorString(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
arg string
|
|
want string
|
|
}{
|
|
{
|
|
name: "no error",
|
|
arg: "",
|
|
want: "",
|
|
},
|
|
{
|
|
name: "normal error",
|
|
arg: "can not open file: \"abc.exe\"",
|
|
want: "can not open file: "abc.exe"",
|
|
},
|
|
{
|
|
name: "line break error",
|
|
arg: "some error:\n\nawesome!",
|
|
want: "some error:<br><br>awesome!",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := SanitizeFlashErrorString(tt.arg); got != tt.want {
|
|
t.Errorf("SanitizeFlashErrorString() = '%v', want '%v'", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|