Refactor external URL detection (#29973)
Follow #29960, `IsExternalURL` is not needed anymore. Add some tests for `RedirectToCurrentSite`
This commit is contained in:
parent
bfa160fc98
commit
ca4107dc96
7 changed files with 40 additions and 62 deletions
|
@ -32,9 +32,11 @@ func IsCurrentGiteaSiteURL(s string) bool {
|
|||
return false
|
||||
}
|
||||
if u.Path != "" {
|
||||
u.Path = "/" + util.PathJoinRelX(u.Path)
|
||||
if !strings.HasSuffix(u.Path, "/") {
|
||||
u.Path += "/"
|
||||
cleanedPath := util.PathJoinRelX(u.Path)
|
||||
if cleanedPath == "" || cleanedPath == "." {
|
||||
u.Path = "/"
|
||||
} else {
|
||||
u.Path += "/" + cleanedPath + "/"
|
||||
}
|
||||
}
|
||||
if urlIsRelative(s, u) {
|
||||
|
|
|
@ -53,6 +53,8 @@ func TestIsCurrentGiteaSiteURL(t *testing.T) {
|
|||
assert.True(t, IsCurrentGiteaSiteURL(s), "good = %q", s)
|
||||
}
|
||||
bad := []string{
|
||||
".",
|
||||
"foo",
|
||||
"/",
|
||||
"//",
|
||||
"\\\\",
|
||||
|
@ -67,5 +69,8 @@ func TestIsCurrentGiteaSiteURL(t *testing.T) {
|
|||
|
||||
setting.AppURL = "http://localhost:3000/"
|
||||
setting.AppSubURL = ""
|
||||
assert.False(t, IsCurrentGiteaSiteURL("//"))
|
||||
assert.False(t, IsCurrentGiteaSiteURL("\\\\"))
|
||||
assert.False(t, IsCurrentGiteaSiteURL("http://localhost"))
|
||||
assert.True(t, IsCurrentGiteaSiteURL("http://localhost:3000?key=val"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue