Skip to content

Commit

Permalink
Merge branch 'treywelsh-B-5914_fix_newline_escaping'
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmontero committed Jul 27, 2022
2 parents fe126c9 + 246e426 commit e4e6b6c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/oca/go/src/goca/dynamic/dyntemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package dynamic

import (
"bytes"
"encoding/xml"
"fmt"
"strconv"
Expand Down Expand Up @@ -74,7 +75,19 @@ func (t *Template) String() string {

// String prints a Pair in OpenNebula syntax
func (p *Pair) String() string {
return fmt.Sprintf("%s=%s", p.XMLName.Local, strconv.Quote(p.Value))

if strconv.CanBackquote(p.Value) {
return fmt.Sprintf("%s=%s", p.XMLName.Local, strconv.Quote(p.Value))
} else {
buf := bytes.NewBufferString(p.XMLName.Local)
buf.WriteString("=\"")
buf.WriteString(strings.ReplaceAll(p.Value, `"`, `\"`))
buf.WriteString(strings.ReplaceAll(p.Value, `\`, `\\`))
buf.WriteByte('"')

return buf.String()

}
}

func (v *Vector) String() string {
Expand Down Expand Up @@ -352,6 +365,13 @@ func NewTemplate() *Template {
return &Template{}
}

// NewTemplate returns a new Template object
func NewVector(name string) *Vector {
return &Vector{
XMLName: xml.Name{Local: name},
}
}

// AddVector creates a new vector in the template
func (t *Template) AddVector(key string) *Vector {
vector := &Vector{XMLName: xml.Name{Local: key}}
Expand Down

0 comments on commit e4e6b6c

Please sign in to comment.