From c7ba5c4dcd13a14f9a0a4fea532ddf550da6c8b7 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Tue, 2 Feb 2021 15:03:33 -0700 Subject: [PATCH] JSON encode schemas URL passed to html template --- api/writer/html.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/writer/html.go b/api/writer/html.go index c908d016..e641e0ea 100644 --- a/api/writer/html.go +++ b/api/writer/html.go @@ -1,6 +1,7 @@ package writer import ( + "encoding/json" "strings" "github.com/rancher/norman/api/builtin" @@ -23,7 +24,7 @@ var ( @@ -51,7 +52,7 @@ func (h *HTMLResponseWriter) Write(apiContext *types.APIContext, code int, obj i schemaSchema := apiContext.Schemas.Schema(&builtin.Version, "schema") headerString := start if schemaSchema != nil { - headerString = strings.Replace(headerString, "%SCHEMAS%", apiContext.URLBuilder.Collection(schemaSchema, apiContext.Version), 1) + headerString = strings.Replace(headerString, "%SCHEMAS%", jsonEncodeURL(apiContext.URLBuilder.Collection(schemaSchema, apiContext.Version)), 1) } var jsurl, cssurl string if h.CSSURL != nil && h.JSURL != nil && h.CSSURL() != "" && h.JSURL() != "" { @@ -73,3 +74,8 @@ func (h *HTMLResponseWriter) Write(apiContext *types.APIContext, code int, obj i apiContext.Response.Write(end) } } + +func jsonEncodeURL(str string) string { + data, _ := json.Marshal(str) + return string(data) +}