Merge pull request #1690 from flant/fix-relative-url
Fix templates which asset path points to external URL
This commit is contained in:
commit
9781e56ba5
@ -184,6 +184,11 @@ func loadTemplates(c webConfig, templatesDir string) (*templates, error) {
|
|||||||
//assetPath is static/main.css
|
//assetPath is static/main.css
|
||||||
//relativeURL("/dex", "/dex/auth", "static/main.css") = "../static/main.css"
|
//relativeURL("/dex", "/dex/auth", "static/main.css") = "../static/main.css"
|
||||||
func relativeURL(serverPath, reqPath, assetPath string) string {
|
func relativeURL(serverPath, reqPath, assetPath string) string {
|
||||||
|
if u, err := url.ParseRequestURI(assetPath); err == nil && u.Scheme != "" {
|
||||||
|
// assetPath points to the external URL, no changes needed
|
||||||
|
return assetPath
|
||||||
|
}
|
||||||
|
|
||||||
splitPath := func(p string) []string {
|
splitPath := func(p string) []string {
|
||||||
res := []string{}
|
res := []string{}
|
||||||
parts := strings.Split(path.Clean(p), "/")
|
parts := strings.Split(path.Clean(p), "/")
|
||||||
|
@ -31,6 +31,13 @@ func TestRelativeURL(t *testing.T) {
|
|||||||
assetPath: "assets/css/main.css",
|
assetPath: "assets/css/main.css",
|
||||||
expected: "../assets/css/main.css",
|
expected: "../assets/css/main.css",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "external-url",
|
||||||
|
serverPath: "/dex",
|
||||||
|
reqPath: "/dex/auth/connector",
|
||||||
|
assetPath: "https://kubernetes.io/images/favicon.png",
|
||||||
|
expected: "https://kubernetes.io/images/favicon.png",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Reference in New Issue
Block a user