Merge pull request #519 from alixander/sql_panic

fix sql constraint array panic
This commit is contained in:
Alexander Wang 2022-12-24 13:16:36 -08:00 committed by GitHub
commit 775691ecaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 0 deletions

View file

@ -19,3 +19,4 @@
- Icons with query parameters are now being escaped to valid SVG XML. [#438](https://github.com/terrastruct/d2/issues/438) - Icons with query parameters are now being escaped to valid SVG XML. [#438](https://github.com/terrastruct/d2/issues/438)
- Fixed connections being clipped if they were at the very top or left edges of the diagram. [#493](https://github.com/terrastruct/d2/pull/493) - Fixed connections being clipped if they were at the very top or left edges of the diagram. [#493](https://github.com/terrastruct/d2/pull/493)
- Fixed edge case where style being defined in same scope as sql_table caused compiler to skip compiling sql_table. [#506](https://github.com/terrastruct/d2/issues/506) - Fixed edge case where style being defined in same scope as sql_table caused compiler to skip compiling sql_table. [#506](https://github.com/terrastruct/d2/issues/506)
- Fixed panic when `constraint` value was not a string value. [#248](https://github.com/terrastruct/d2/issues/248)

View file

@ -688,6 +688,10 @@ func (c *compiler) compileSQLTable(obj *d2graph.Object) {
continue continue
} }
if n.MapKey.Key.Path[0].Unbox().ScalarString() == "constraint" { 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() d2Col.Constraint = n.MapKey.Value.StringBox().Unbox().ScalarString()
} }
} }

View file

@ -1668,6 +1668,16 @@ choo: {
tassert.Equal(t, 3, len(g.Objects)) 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 { 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"
}
]
}
}