From 70505b258d1584b723212340818535507cd00f93 Mon Sep 17 00:00:00 2001 From: "m.nabokikh" Date: Fri, 17 Apr 2020 00:43:31 +0400 Subject: [PATCH] Fix templates with asset paths that point to external URL Signed-off-by: m.nabokikh --- server/templates.go | 5 +++++ server/templates_test.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/server/templates.go b/server/templates.go index 4947a102..bc2c81eb 100644 --- a/server/templates.go +++ b/server/templates.go @@ -176,6 +176,11 @@ func loadTemplates(c webConfig, templatesDir string) (*templates, error) { //assetPath is static/main.css //relativeURL("/dex", "/dex/auth", "static/main.css") = "../static/main.css" 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 { res := []string{} parts := strings.Split(path.Clean(p), "/") diff --git a/server/templates_test.go b/server/templates_test.go index 5ead66e5..defb2e5e 100644 --- a/server/templates_test.go +++ b/server/templates_test.go @@ -31,6 +31,13 @@ func TestRelativeURL(t *testing.T) { assetPath: "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 {