I dont know how to print values out of an array into a html template This is my struct
type Lampen struct {
Values [10]string
}
and my code for prasing the template is the following
title := "moodlights"
p := &lampen.Lampen{}
err := p.LoadLampValues(title)
if err != nil {
log.Printf("Error loading Config File")
for i := range p.Values {
p.Values[i] = "0"
}
}
t, _ := template.ParseFiles("template.html")
t.Execute(w, p)
What it does is, that it loads the Values from a JSON File. But now I dont know how to print the Values into the html file. What works is the following:
<div>Lampe0: <input type="text" name="Lampe0" value={{index .Values 0}} maxlength="6"></div>
But of course it does not escape the Values in the html so XSS is a problem.
Update: For Cross site Scripting the Problem I want to show here is: If the json file contains the following
"Values": [
"\u003e",
"",
"",
"",
"",
"",
"",
"",
"",
""
]
which is the equivalent to >, the html printed will be
<div>Lampe0: <input type="text" name="Lampe0" value=> maxlength="6"></div>
So its not escaped
How to printf it into the html so its escaped?
Update2: The old working Version with escaping can be seen at https://github.com/Binary-Kitchen/gokitchenmood