diff --git a/d2oracle/get.go b/d2oracle/get.go index f45661e68..f24178efd 100644 --- a/d2oracle/get.go +++ b/d2oracle/get.go @@ -3,6 +3,8 @@ package d2oracle import ( "fmt" + "oss.terrastruct.com/d2/d2ast" + "oss.terrastruct.com/d2/d2format" "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2parser" ) @@ -97,5 +99,5 @@ func GetID(key string) string { return "" } - return mk.Key.Path[len(mk.Key.Path)-1].Unbox().ScalarString() + return d2format.Format(d2ast.RawString(mk.Key.Path[len(mk.Key.Path)-1].Unbox().ScalarString(), true)) } diff --git a/d2oracle/get_test.go b/d2oracle/get_test.go index 21e695506..d98f7108e 100644 --- a/d2oracle/get_test.go +++ b/d2oracle/get_test.go @@ -18,3 +18,9 @@ func TestIsLabelKeyID(t *testing.T) { assert.Equal(t, false, d2oracle.IsLabelKeyID("x", "y")) assert.Equal(t, false, d2oracle.IsLabelKeyID("x->y", "y")) } + +func TestGetID(t *testing.T) { + t.Parallel() + + assert.Equal(t, `"y (z)"`, d2oracle.GetID(`y (z)`)) +}