add class array footgun
This commit is contained in:
parent
7d56c2dbb4
commit
0d4392eac2
3 changed files with 44 additions and 0 deletions
|
|
@ -147,6 +147,21 @@ func (c *compiler) compileMap(obj *d2graph.Object, m *d2ir.Map) {
|
|||
classMap := m.GetClassMap(className)
|
||||
if classMap != nil {
|
||||
c.compileMap(obj, classMap)
|
||||
} else {
|
||||
if strings.Contains(className, ",") {
|
||||
split := strings.Split(className, ",")
|
||||
allFound := true
|
||||
for _, maybeClassName := range split {
|
||||
maybeClassName = strings.TrimSpace(maybeClassName)
|
||||
if m.GetClassMap(maybeClassName) == nil {
|
||||
allFound = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if allFound {
|
||||
c.errorf(class.LastRef().AST(), `class "%s" not found. Did you mean to use ";" to separate array items?`, className)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2482,6 +2482,23 @@ nostar -> 1star: { class: [path; path2] }
|
|||
tassert.Equal(t, "2", g.Edges[0].Style.StrokeWidth.Value)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "comma-array-class",
|
||||
|
||||
text: `classes: {
|
||||
dragon_ball: {
|
||||
label: ""
|
||||
shape: circle
|
||||
style.fill: orange
|
||||
}
|
||||
path: {
|
||||
label: "then"
|
||||
style.stroke-width: 4
|
||||
}
|
||||
}
|
||||
nostar: { class: [dragon_ball, path] }`,
|
||||
expErr: `d2/testdata/d2compiler/TestCompile/comma-array-class.d2:12:11: class "dragon_ball, path" not found. Did you mean to use ";" to separate array items?`,
|
||||
},
|
||||
{
|
||||
name: "reordered-classes",
|
||||
text: `classes: {
|
||||
|
|
|
|||
12
testdata/d2compiler/TestCompile/comma-array-class.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/comma-array-class.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"graph": null,
|
||||
"err": {
|
||||
"ioerr": null,
|
||||
"errs": [
|
||||
{
|
||||
"range": "d2/testdata/d2compiler/TestCompile/comma-array-class.d2,11:10:157-11:15:162",
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/comma-array-class.d2:12:11: class \"dragon_ball, path\" not found. Did you mean to use \";\" to separate array items?"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue