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
|
text: `null
|
||||||
`,
|
`,
|
||||||
assertions: func(t *testing.T, g *d2graph.Graph) {
|
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)
|
tassert.Equal(t, "null", g.Objects[0].IDVal)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,10 @@ func escapeUnquotedValue(s string, inKey bool) string {
|
||||||
return `""`
|
return `""`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.EqualFold(s, "null") {
|
||||||
|
return `'null'`
|
||||||
|
}
|
||||||
|
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
for i, r := range s {
|
for i, r := range s {
|
||||||
switch r {
|
switch r {
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ func TestEscapeUnquoted(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "null",
|
name: "null",
|
||||||
str: `null`,
|
str: `null`,
|
||||||
exp: `\null`,
|
exp: `'null'`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty",
|
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,
|
"edges": null,
|
||||||
"objects": [
|
"objects": [
|
||||||
{
|
{
|
||||||
"id": "null",
|
"id": "'null'",
|
||||||
"id_val": "null",
|
"id_val": "null",
|
||||||
"label_dimensions": {
|
"label_dimensions": {
|
||||||
"width": 0,
|
"width": 0,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue