diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 4156961d7..d644b7fa9 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -2113,7 +2113,7 @@ b tassert.Equal(t, 5, len(g.Objects)) tassert.Equal(t, "a", g.Objects[0].ID) tassert.Equal(t, "b", g.Objects[1].ID) - tassert.Equal(t, `04:20,11:20`, g.Objects[2].ID) + tassert.Equal(t, `"04:20,11:20"`, g.Objects[2].ID) tassert.Equal(t, `loop through each table`, g.Objects[3].ID) tassert.Equal(t, 1, len(g.Objects[0].ChildrenArray)) tassert.Equal(t, 0, len(g.Objects[1].ChildrenArray)) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 30d9123c5..0776849ab 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -694,7 +694,10 @@ func (obj *Object) Text() *d2target.MText { } } -func (obj *Object) newObject(id string) *Object { +func (obj *Object) newObject(ids d2ast.String) *Object { + id := d2format.Format(&d2ast.KeyPath{ + Path: []*d2ast.StringBox{d2ast.MakeValueBox(d2ast.RawString(ids.ScalarString(), true)).StringBox()}, + }) idval := id k, _ := d2parser.ParseKey(id) if k != nil && len(k.Path) > 0 { @@ -901,9 +904,12 @@ func (obj *Object) EnsureChild(ida []d2ast.String) *Object { return obj.Parent.EnsureChild(ida) } - child, ok := obj.Children[strings.ToLower(id.ScalarString())] + head := d2format.Format(&d2ast.KeyPath{ + Path: []*d2ast.StringBox{d2ast.MakeValueBox(d2ast.RawString(id.ScalarString(), true)).StringBox()}, + }) + child, ok := obj.Children[strings.ToLower(head)] if !ok { - child = obj.newObject(id.ScalarString()) + child = obj.newObject(id) } if len(ida) >= 1 { diff --git a/testdata/d2compiler/TestCompile/escaped_id.exp.json b/testdata/d2compiler/TestCompile/escaped_id.exp.json index 43ac9198a..796618579 100644 --- a/testdata/d2compiler/TestCompile/escaped_id.exp.json +++ b/testdata/d2compiler/TestCompile/escaped_id.exp.json @@ -56,8 +56,8 @@ "edges": null, "objects": [ { - "id": "b\nb", - "id_val": "b", + "id": "\"b\\nb\"", + "id_val": "b\nb", "references": [ { "key": { @@ -82,7 +82,7 @@ ], "attributes": { "label": { - "value": "b" + "value": "b\nb" }, "labelDimensions": { "width": 0, diff --git a/testdata/d2compiler/TestCompile/name-with-dot-underscore.exp.json b/testdata/d2compiler/TestCompile/name-with-dot-underscore.exp.json index 746a719a0..7c2ec3cf4 100644 --- a/testdata/d2compiler/TestCompile/name-with-dot-underscore.exp.json +++ b/testdata/d2compiler/TestCompile/name-with-dot-underscore.exp.json @@ -291,8 +291,8 @@ "zIndex": 0 }, { - "id": "D.E", - "id_val": "D", + "id": "\"D.E\"", + "id_val": "D.E", "references": [ { "key": { @@ -317,7 +317,7 @@ ], "attributes": { "label": { - "value": "D" + "value": "D.E" }, "labelDimensions": { "width": 0, diff --git a/testdata/d2compiler/TestCompile/null.exp.json b/testdata/d2compiler/TestCompile/null.exp.json index e3045facb..9781daf23 100644 --- a/testdata/d2compiler/TestCompile/null.exp.json +++ b/testdata/d2compiler/TestCompile/null.exp.json @@ -56,7 +56,7 @@ "edges": null, "objects": [ { - "id": "null", + "id": "'null'", "id_val": "null", "references": [ { diff --git a/testdata/d2compiler/TestCompile/sequence-timestamp.exp.json b/testdata/d2compiler/TestCompile/sequence-timestamp.exp.json index 1799ac343..4c90eaac0 100644 --- a/testdata/d2compiler/TestCompile/sequence-timestamp.exp.json +++ b/testdata/d2compiler/TestCompile/sequence-timestamp.exp.json @@ -442,8 +442,8 @@ "zIndex": 0 }, { - "id": "04:20,11:20", - "id_val": "04", + "id": "\"04:20,11:20\"", + "id_val": "04:20,11:20", "references": [ { "key": { @@ -468,7 +468,7 @@ ], "attributes": { "label": { - "value": "04" + "value": "04:20,11:20" }, "labelDimensions": { "width": 0, @@ -532,8 +532,8 @@ "zIndex": 0 }, { - "id": "start_time = datetime.datetime.now", - "id_val": "start_time = datetime", + "id": "\"start_time = datetime.datetime.now\"", + "id_val": "start_time = datetime.datetime.now", "references": [ { "key": { @@ -569,7 +569,7 @@ ], "attributes": { "label": { - "value": "start_time = datetime" + "value": "start_time = datetime.datetime.now" }, "labelDimensions": { "width": 0,