Skip to content

Commit

Permalink
Fix templates with asset paths that point to external URL
Browse files Browse the repository at this point in the history
Signed-off-by: m.nabokikh <[email protected]>
  • Loading branch information
nabokihms committed Jul 6, 2020
1 parent 1d892c6 commit 70505b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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), "/")
Expand Down
7 changes: 7 additions & 0 deletions server/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 70505b2

Please sign in to comment.