Skip to content

Commit

Permalink
Merge pull request #389 from ibuildthecloud/master
Browse files Browse the repository at this point in the history
JSON encode schemas URL passed to html template
  • Loading branch information
ibuildthecloud authored Feb 9, 2021
2 parents 693d65a + c7ba5c4 commit 63e1cb5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions api/writer/html.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package writer

import (
"encoding/json"
"strings"

"github.com/rancher/norman/api/builtin"
Expand All @@ -23,7 +24,7 @@ var (
<script>
var user = "admin";
var curlUser='${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}';
var schemas="%SCHEMAS%";
var schemas=%SCHEMAS%;
var data =
`
end = []byte(`</script>
Expand Down Expand Up @@ -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() != "" {
Expand All @@ -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)
}

0 comments on commit 63e1cb5

Please sign in to comment.