[#275] added support to customize the default user email templates from the Admin UI

This commit is contained in:
Gani Georgiev
2022-08-14 19:30:45 +03:00
parent 1de56d3d9e
commit 7d10d20de1
47 changed files with 1648 additions and 1188 deletions
+29
View File
@@ -0,0 +1,29 @@
package rest
import (
"net/url"
"path"
"strings"
)
// NormalizeUrl removes duplicated slashes from a url path.
func NormalizeUrl(originalUrl string) (string, error) {
u, err := url.Parse(originalUrl)
if err != nil {
return "", err
}
hasSlash := strings.HasSuffix(u.Path, "/")
// clean up path by removing duplicated /
u.Path = path.Clean(u.Path)
u.RawPath = path.Clean(u.RawPath)
// restore original trailing slash
if hasSlash && !strings.HasSuffix(u.Path, "/") {
u.Path += "/"
u.RawPath += "/"
}
return u.String(), nil
}
+40
View File
@@ -0,0 +1,40 @@
package rest_test
import (
"testing"
"github.com/pocketbase/pocketbase/tools/rest"
)
func TestNormalizeUrl(t *testing.T) {
scenarios := []struct {
url string
expectError bool
expectUrl string
}{
{":/", true, ""},
{"./", false, "./"},
{"../../test////", false, "../../test/"},
{"/a/b/c", false, "/a/b/c"},
{"a/////b//c/", false, "a/b/c/"},
{"/a/////b//c", false, "/a/b/c"},
{"///a/b/c", false, "/a/b/c"},
{"//a/b/c", false, "//a/b/c"}, // preserve "auto-schema"
{"http://a/b/c", false, "http://a/b/c"},
{"a//bc?test=1//dd", false, "a/bc?test=1//dd"}, // only the path is normalized
{"a//bc?test=1#12///3", false, "a/bc?test=1#12///3"}, // only the path is normalized
}
for i, s := range scenarios {
result, err := rest.NormalizeUrl(s.url)
hasErr := err != nil
if hasErr != s.expectError {
t.Errorf("(%d) Expected hasErr %v, got %v", i, s.expectError, hasErr)
}
if result != s.expectUrl {
t.Errorf("(%d) Expected url %q, got %q", i, s.expectUrl, result)
}
}
}