From 4783cf83b8d34dc2e8a4727c834a9bf6cf5b865e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Elek?= Date: Wed, 23 Aug 2023 10:25:46 +0200 Subject: [PATCH] standalone: fix quotation problems in generated XML / shell files Change-Id: I5d8e563089977cb431f27d4ecc4d8519fe5b24ba --- pkg/runtime/standalone/intellij.xml | 4 ++-- pkg/runtime/standalone/start.sh | 2 +- pkg/runtime/standalone/write.go | 13 +++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/runtime/standalone/intellij.xml b/pkg/runtime/standalone/intellij.xml index 8af9520..d0e0936 100644 --- a/pkg/runtime/standalone/intellij.xml +++ b/pkg/runtime/standalone/intellij.xml @@ -3,10 +3,10 @@ factoryName="Go Application"> - + {{ range $k, $v := .Service.Environment}} - {{end}} + {{end}} diff --git a/pkg/runtime/standalone/start.sh b/pkg/runtime/standalone/start.sh index b866936..1ff5b94 100644 --- a/pkg/runtime/standalone/start.sh +++ b/pkg/runtime/standalone/start.sh @@ -10,7 +10,7 @@ cleanup(){ trap cleanup EXIT {{ range $k,$v := .Service.Environment}} -export {{$k}}="{{$v}}"{{end}} +export {{$k}}="{{Safe $v}}"{{end}} mkdir -p ./{{.Service.ID.Name}}/{{.Service.ID.Instance}} #RUN diff --git a/pkg/runtime/standalone/write.go b/pkg/runtime/standalone/write.go index a6cd452..72ed9ac 100644 --- a/pkg/runtime/standalone/write.go +++ b/pkg/runtime/standalone/write.go @@ -95,6 +95,16 @@ func (c *Standalone) writeService(s *service) error { t, err := template.New("start.sh"). Funcs(map[string]interface{}{ "HasPrefix": strings.HasPrefix, + "Safe": func(p string) string { + out := "" + for i := 0; i < len(p); i++ { + if i > 0 && p[i] == '"' && p[i-1] != '\\' { + out += "\\" + } + out += string(p[i]) + } + return out + }, }). Parse(string(startTemplate)) if err != nil { @@ -142,6 +152,9 @@ func (c *Standalone) writeIntelliJRunner(s *service) error { return a }, "Join": strings.Join, + "Safe": func(p string) string { + return strings.ReplaceAll(p, "\"", """) + }, }). Parse(string(intelliJTemplate)) if err != nil {