Skip to content

Commit

Permalink
Merge pull request #2078 from alixander/prevent-oob
Browse files Browse the repository at this point in the history
fix oob
  • Loading branch information
alixander authored Aug 27, 2024
2 parents b6a9268 + e93a60d commit e2e8878
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
11 changes: 11 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,17 @@ layers: {
tassert.Equal(t, "root.layers.a", g.Layers[2].Layers[0].Objects[2].Link.Value)
},
},
{
name: "link-beyond-import-root",
text: `...@x`,
files: map[string]string{
"x.d2": `x.link: _.layers.z
`,
},
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, (*d2graph.Scalar)(nil), g.Objects[0].Link)
},
},
{
name: "link-board-underscore-not-found",
text: `x
Expand Down
4 changes: 4 additions & 0 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ func (c *compiler) ignoreLazyGlob(n Node) bool {
func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) {
nodeBoardKind := NodeBoardKind(m)
importIDA := IDA(importF)
FIELDS_LOOP:
for _, f := range m.Fields {
if f.Name == "link" {
if nodeBoardKind != "" {
Expand All @@ -922,6 +923,9 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) {

for _, id := range linkIDA[1:] {
if id == "_" {
if len(linkIDA) < 2 || len(importIDA) < 2 {
continue FIELDS_LOOP
}
linkIDA = append([]string{linkIDA[0]}, linkIDA[2:]...)
importIDA = importIDA[:len(importIDA)-2]
} else {
Expand Down
114 changes: 114 additions & 0 deletions testdata/d2compiler/TestCompile/link-beyond-import-root.exp.json

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

0 comments on commit e2e8878

Please sign in to comment.