Skip to content

Commit

Permalink
Merge pull request #2270 from alixander/double-nested-set
Browse files Browse the repository at this point in the history
d2oracle: fix setting nested import
  • Loading branch information
alixander authored Jan 8, 2025
2 parents ebeb8ba + c22883e commit c50fab7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions d2oracle/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions d2oracle/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down
4 changes: 4 additions & 0 deletions testdata/d2oracle/TestSet/import/10.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c50fab7

Please sign in to comment.