Merge pull request #2270 from alixander/double-nested-set

d2oracle: fix setting nested import
This commit is contained in:
Alexander Wang 2025-01-08 13:23:53 -07:00 committed by GitHub
commit c50fab758a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View file

@ -42,6 +42,9 @@ func Create(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph,
} }
// TODO beter name // TODO beter name
baseAST = boardG.BaseAST baseAST = boardG.BaseAST
if baseAST == nil {
return nil, "", fmt.Errorf("board %v cannot be modified through this file", boardPath)
}
} }
newKey, edge, err := generateUniqueKey(boardG, key, nil, nil) newKey, edge, err := generateUniqueKey(boardG, key, nil, nil)
@ -98,6 +101,9 @@ func Set(g *d2graph.Graph, boardPath []string, key string, tag, value *string) (
} }
// TODO beter name // TODO beter name
baseAST = boardG.BaseAST baseAST = boardG.BaseAST
if baseAST == nil {
return nil, fmt.Errorf("board %v cannot be modified through this file", boardPath)
}
} }
err = _set(boardG, baseAST, key, tag, value) err = _set(boardG, baseAST, key, tag, value)
@ -142,6 +148,9 @@ func ReconnectEdge(g *d2graph.Graph, boardPath []string, edgeKey string, srcKey,
} }
// TODO beter name // TODO beter name
baseAST = boardG.BaseAST baseAST = boardG.BaseAST
if baseAST == nil {
return nil, fmt.Errorf("board %v cannot be modified through this file", boardPath)
}
} }
obj := boardG.Root obj := boardG.Root
@ -946,6 +955,9 @@ func Delete(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph,
} }
// TODO beter name // TODO beter name
baseAST = boardG.BaseAST baseAST = boardG.BaseAST
if baseAST == nil {
return nil, fmt.Errorf("board %v cannot be modified through this file", boardPath)
}
} }
g2, err := deleteReserved(g, boardPath, baseAST, mk) g2, err := deleteReserved(g, boardPath, baseAST, mk)
@ -1761,6 +1773,9 @@ func move(g *d2graph.Graph, boardPath []string, key, newKey string, includeDesce
} }
// TODO beter name // TODO beter name
baseAST = boardG.BaseAST baseAST = boardG.BaseAST
if baseAST == nil {
return nil, fmt.Errorf("board %v cannot be modified through this file", boardPath)
}
} }
newKey, _, err := generateUniqueKey(boardG, newKey, nil, nil) newKey, _, err := generateUniqueKey(boardG, newKey, nil, nil)

View file

@ -2467,6 +2467,28 @@ layers: {
(a -> b)[0].style.stroke: red (a -> b)[0].style.stroke: red
`, `,
}, },
{
name: "import/10",
text: `heyn
layers: {
man: {...@meow}
}
`,
fsTexts: map[string]string{
"meow.d2": `layers: {
1: {
asdf
}
}
`,
},
boardPath: []string{"man", "1"},
key: `asdf.link`,
value: go2.Pointer(`_._`),
expErr: `failed to set "asdf.link" to "\"_._\"": board [man 1] cannot be modified through this file`,
},
{ {
name: "label-near/1", name: "label-near/1",

4
testdata/d2oracle/TestSet/import/10.exp.json generated vendored Normal file
View file

@ -0,0 +1,4 @@
{
"graph": null,
"err": "failed to set \"asdf.link\" to \"\\\"_._\\\"\": board [man 1] cannot be modified through this file"
}