fix: properly quote hosts to ensure valid formatting (#95)

This commit is contained in:
silenceqi 2025-01-23 16:04:52 +08:00 committed by GitHub
parent f3417ee6de
commit 16c08e745f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 4 deletions

View File

@ -805,11 +805,13 @@ func (module *Module) initializeTemplate(w http.ResponseWriter, r *http.Request,
endpoints = append(endpoints, endpoint)
}
}
endpointsStr := fmt.Sprintf("[%s]", strings.Join(endpoints, ", "))
return w.Write([]byte(endpointsStr))
endpointBytes := util.MustToJSONBytes(endpoints)
endpointBytes = bytes.ReplaceAll(endpointBytes, []byte("\""), []byte("\\\""))
return w.Write(endpointBytes)
case "SETUP_HOSTS":
hostsStr := fmt.Sprintf("[%s]", strings.Join(request.Cluster.Hosts, ", "))
return w.Write([]byte(hostsStr))
hostsBytes := util.MustToJSONBytes(request.Cluster.Hosts)
hostsBytes = bytes.ReplaceAll(hostsBytes, []byte("\""), []byte("\\\""))
return w.Write(hostsBytes)
case "SETUP_TEMPLATE_NAME":
return w.Write([]byte(cfg1.TemplateName))
case "SETUP_INDEX_PREFIX":