Skip to content

Commit

Permalink
standalone: fix quotation problems in generated XML / shell files
Browse files Browse the repository at this point in the history
Change-Id: I5d8e563089977cb431f27d4ecc4d8519fe5b24ba
  • Loading branch information
elek authored and Elek, Márton committed Aug 29, 2023
1 parent ef49d98 commit 4783cf8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/runtime/standalone/intellij.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
factoryName="Go Application">
<module name="{{ .Package }}"/>
<working_directory value="$PROJECT_DIR$/.run"/>
<parameters value="{{ Join (Tail .Service.Command) " "}}"/>
<parameters value="{{ Safe (Join (Tail .Service.Command) " ")}}"/>
<envs>
{{ range $k, $v := .Service.Environment}}
<env name="{{$k}}" value="{{$v}}"/>{{end}}
<env name="{{$k}}" value="{{Safe $v}}"/>{{end}}
</envs>
<kind value="PACKAGE"/>
<package value="storj.io/{{ .Package }}/cmd/{{ .Executable }}"/>
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/standalone/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pkg/runtime/standalone/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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, "\"", "&quot;")
},
}).
Parse(string(intelliJTemplate))
if err != nil {
Expand Down

0 comments on commit 4783cf8

Please sign in to comment.