diff --git a/d2format/format.go b/d2format/format.go index a2acb4b6b..63bebcadd 100644 --- a/d2format/format.go +++ b/d2format/format.go @@ -127,7 +127,7 @@ func (p *printer) blockComment(bc *d2ast.BlockComment) { } func (p *printer) interpolationBoxes(boxes []d2ast.InterpolationBox, isDoubleString bool) { - for _, b := range boxes { + for i, b := range boxes { if b.Substitution != nil { p.substitution(b.Substitution) continue @@ -140,6 +140,11 @@ func (p *printer) interpolationBoxes(boxes []d2ast.InterpolationBox, isDoubleStr s = escapeUnquotedValue(*b.String, p.inKey) } b.StringRaw = &s + } else if i > 0 && boxes[i-1].Substitution != nil { + // If this string follows a substitution, we need to make sure to use + // the actual string content, not the raw value which might be incorrect + s := *b.String + b.StringRaw = &s } if !isDoubleString { if _, ok := d2ast.ReservedKeywords[strings.ToLower(*b.StringRaw)]; ok { diff --git a/d2format/format_test.go b/d2format/format_test.go index ab90ea276..ed7c9e97a 100644 --- a/d2format/format_test.go +++ b/d2format/format_test.go @@ -892,6 +892,19 @@ scenarios: {} steps: asdf `, exp: `k +`, + }, + { + name: "vars", + in: `vars: { + a: "a" + b: "X${a})" +} +`, + exp: `vars: { + a: "a" + b: "X${a})" +} `, }, }