d2compiler: newlines in sql_tables are made invalid
This commit is contained in:
parent
021011afbd
commit
b70f9783e2
3 changed files with 42 additions and 10 deletions
|
|
@ -1047,16 +1047,18 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) {
|
||||||
|
|
||||||
func (c *compiler) validateLabels(g *d2graph.Graph) {
|
func (c *compiler) validateLabels(g *d2graph.Graph) {
|
||||||
for _, obj := range g.Objects {
|
for _, obj := range g.Objects {
|
||||||
if !strings.EqualFold(obj.Shape.Value, d2target.ShapeText) {
|
if strings.EqualFold(obj.Shape.Value, d2target.ShapeText) {
|
||||||
continue
|
|
||||||
}
|
|
||||||
if obj.Attributes.Language != "" {
|
if obj.Attributes.Language != "" {
|
||||||
// blockstrings have already been validated
|
// blockstrings have already been validated
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.TrimSpace(obj.Label.Value) == "" {
|
if strings.TrimSpace(obj.Label.Value) == "" {
|
||||||
c.errorf(obj.Label.MapKey, "shape text must have a non-empty label")
|
c.errorf(obj.Label.MapKey, "shape text must have a non-empty label")
|
||||||
continue
|
}
|
||||||
|
} else if strings.EqualFold(obj.Shape.Value, d2target.ShapeSQLTable) {
|
||||||
|
if strings.Contains(obj.Label.Value, "\n") {
|
||||||
|
c.errorf(obj.Label.MapKey, "shape sql_table cannot have newlines")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3114,6 +3114,21 @@ layers: {
|
||||||
"y/n.d2": "p",
|
"y/n.d2": "p",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "sql-table-header-newline",
|
||||||
|
text: `x: {
|
||||||
|
shape: sql_table
|
||||||
|
label: hello\nworld
|
||||||
|
}
|
||||||
|
|
||||||
|
y: "hello\nworld" {
|
||||||
|
shape: sql_table
|
||||||
|
hi: there
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/sql-table-header-newline.d2:3:3: shape sql_table cannot have newlines
|
||||||
|
d2/testdata/d2compiler/TestCompile/sql-table-header-newline.d2:6:1: shape sql_table cannot have newlines`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
|
||||||
15
testdata/d2compiler/TestCompile/sql-table-header-newline.exp.json
generated
vendored
Normal file
15
testdata/d2compiler/TestCompile/sql-table-header-newline.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/sql-table-header-newline.d2,2:2:26-2:21:45",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/sql-table-header-newline.d2:3:3: shape sql_table cannot have newlines"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/sql-table-header-newline.d2,5:0:49-8:1:100",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/sql-table-header-newline.d2:6:1: shape sql_table cannot have newlines"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue