fix sql constraint array panic

This commit is contained in:
Alexander Wang 2022-12-24 13:11:45 -08:00
parent 4eda74ada4
commit 3a6834662d
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
3 changed files with 26 additions and 0 deletions

View file

@ -688,6 +688,10 @@ func (c *compiler) compileSQLTable(obj *d2graph.Object) {
continue
}
if n.MapKey.Key.Path[0].Unbox().ScalarString() == "constraint" {
if n.MapKey.Value.StringBox().Unbox() == nil {
c.errorf(n.MapKey.GetRange().Start, n.MapKey.GetRange().End, "constraint value must be a string")
return
}
d2Col.Constraint = n.MapKey.Value.StringBox().Unbox().ScalarString()
}
}

View file

@ -1668,6 +1668,16 @@ choo: {
tassert.Equal(t, 3, len(g.Objects))
},
},
{
name: "sql-panic",
text: `test {
shape: sql_table
test_id: varchar(64) {constraint: [primary_key, foreign_key]}
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/sql-panic.d2:3:27: constraint value must be a string
`,
},
}
for _, tc := range testCases {

12
testdata/d2compiler/TestCompile/sql-panic.exp.json generated vendored Normal file
View file

@ -0,0 +1,12 @@
{
"graph": null,
"err": {
"ioerr": null,
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/sql-panic.d2,2:26:54-2:64:92",
"errmsg": "d2/testdata/d2compiler/TestCompile/sql-panic.d2:3:27: constraint value must be a string"
}
]
}
}