d2ast: Fix RawString test with ampersand

This commit is contained in:
Anmol Sethi 2023-07-29 17:50:40 -07:00
parent 60a19cffde
commit 0f45d2b082
No known key found for this signature in database
GPG key ID: 8CEF1878FF10ADEB

View file

@ -1099,12 +1099,11 @@ type InterpolationBox struct {
// & is only special if it begins a key. // & is only special if it begins a key.
// - is only special if followed by another - in a key. // - is only special if followed by another - in a key.
// ' " and | are only special if they begin an unquoted key or value. // ' " and | are only special if they begin an unquoted key or value.
var UnquotedKeySpecials = string([]rune{'#', ';', '\n', '\\', '{', '}', '[', ']', '\'', '"', '|', ':', '.', '-', '<', '>', '*', '&', '(', ')', '@'}) var UnquotedKeySpecials = string([]rune{'#', ';', '\n', '\\', '{', '}', '[', ']', '\'', '"', '|', ':', '.', '-', '<', '>', '*', '&', '(', ')', '@', '&'})
var UnquotedValueSpecials = string([]rune{'#', ';', '\n', '\\', '{', '}', '[', ']', '\'', '"', '|', '$', '@'}) var UnquotedValueSpecials = string([]rune{'#', ';', '\n', '\\', '{', '}', '[', ']', '\'', '"', '|', '$', '@'})
// RawString returns s in a AST String node that can format s in the most aesthetically // RawString returns s in a AST String node that can format s in the most aesthetically
// pleasing way. // pleasing way.
// TODO: Return StringBox
func RawString(s string, inKey bool) String { func RawString(s string, inKey bool) String {
if s == "" { if s == "" {
return FlatDoubleQuotedString(s) return FlatDoubleQuotedString(s)
@ -1117,10 +1116,6 @@ func RawString(s string, inKey bool) String {
if i+1 < len(s) && s[i+1] != '-' { if i+1 < len(s) && s[i+1] != '-' {
continue continue
} }
case '&':
if i > 0 {
continue
}
} }
if strings.ContainsRune(UnquotedKeySpecials, r) { if strings.ContainsRune(UnquotedKeySpecials, r) {
if !strings.ContainsRune(s, '"') { if !strings.ContainsRune(s, '"') {