d2format: Escape null correctly
This commit is contained in:
parent
81b8606d8a
commit
dd1de57200
4 changed files with 7 additions and 3 deletions
|
|
@ -1656,7 +1656,7 @@ choo: {
|
|||
text: `null
|
||||
`,
|
||||
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||
tassert.Equal(t, "null", g.Objects[0].ID)
|
||||
tassert.Equal(t, "'null'", g.Objects[0].ID)
|
||||
tassert.Equal(t, "null", g.Objects[0].IDVal)
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -47,6 +47,10 @@ func escapeUnquotedValue(s string, inKey bool) string {
|
|||
return `""`
|
||||
}
|
||||
|
||||
if strings.EqualFold(s, "null") {
|
||||
return `'null'`
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
for i, r := range s {
|
||||
switch r {
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ func TestEscapeUnquoted(t *testing.T) {
|
|||
{
|
||||
name: "null",
|
||||
str: `null`,
|
||||
exp: `\null`,
|
||||
exp: `'null'`,
|
||||
},
|
||||
{
|
||||
name: "empty",
|
||||
|
|
|
|||
2
testdata/d2compiler/TestCompile/null.exp.json
generated
vendored
2
testdata/d2compiler/TestCompile/null.exp.json
generated
vendored
|
|
@ -53,7 +53,7 @@
|
|||
"edges": null,
|
||||
"objects": [
|
||||
{
|
||||
"id": "null",
|
||||
"id": "'null'",
|
||||
"id_val": "null",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
|
|
|
|||
Loading…
Reference in a new issue