diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 25e53200e..ff0403d6e 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -42,6 +42,9 @@ func Create(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph, } // TODO beter name 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) @@ -98,6 +101,9 @@ func Set(g *d2graph.Graph, boardPath []string, key string, tag, value *string) ( } // TODO beter name 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) @@ -142,6 +148,9 @@ func ReconnectEdge(g *d2graph.Graph, boardPath []string, edgeKey string, srcKey, } // TODO beter name baseAST = boardG.BaseAST + if baseAST == nil { + return nil, fmt.Errorf("board %v cannot be modified through this file", boardPath) + } } obj := boardG.Root @@ -946,6 +955,9 @@ func Delete(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph, } // TODO beter name 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) @@ -1761,6 +1773,9 @@ func move(g *d2graph.Graph, boardPath []string, key, newKey string, includeDesce } // TODO beter name 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) diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index 7b8d139be..3d37814f0 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -2467,6 +2467,28 @@ layers: { (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", diff --git a/testdata/d2oracle/TestSet/import/10.exp.json b/testdata/d2oracle/TestSet/import/10.exp.json new file mode 100644 index 000000000..909ef237e --- /dev/null +++ b/testdata/d2oracle/TestSet/import/10.exp.json @@ -0,0 +1,4 @@ +{ + "graph": null, + "err": "failed to set \"asdf.link\" to \"\\\"_._\\\"\": board [man 1] cannot be modified through this file" +}