diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 16439d1e5..0541fb231 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -5,4 +5,5 @@ #### Bugfixes ⛑️ - Fix importing files that override an existing value with an array. [#1762](https://github.com/terrastruct/d2/pull/1762) -- Fixed missing unfilled triangle arrowheads when sketch flag is on. [#1763](https://github.com/terrastruct/d2/pull/1763) +- Fixes missing unfilled triangle arrowheads when sketch flag is on. [#1763](https://github.com/terrastruct/d2/pull/1763) +- Fixes a bug where the render target could be incorrect if the target path contains "index". [#1764](https://github.com/terrastruct/d2/pull/1764) diff --git a/d2target/d2target.go b/d2target/d2target.go index b369af4e7..c8af3fb7f 100644 --- a/d2target/d2target.go +++ b/d2target/d2target.go @@ -79,7 +79,7 @@ func (d *Diagram) GetBoard(boardPath []string) *Diagram { head := boardPath[0] - if head == "index" { + if len(boardPath) == 1 && d.Name == head { return d } diff --git a/e2etests-cli/main_test.go b/e2etests-cli/main_test.go index d58e81dd7..ba496253a 100644 --- a/e2etests-cli/main_test.go +++ b/e2etests-cli/main_test.go @@ -299,6 +299,56 @@ scenarios: { assert.ErrorString(t, err, `failed to wait xmain test: e2etests-cli/d2: failed to compile target-invalid.d2: render target "b" not found`) }, }, + { + name: "target-nested-index", + run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) { + writeFile(t, dir, "target-nested-index.d2", `a +layers: { + l1: { + b + layers: { + index: { + c + layers: { + l3: { + d + } + } + } + } + } +}`) + err := runTestMain(t, ctx, dir, env, "--target", `l1.index.l3`, "target-nested-index.d2", "target-nested-index.svg") + assert.Success(t, err) + svg := readFile(t, dir, "target-nested-index.svg") + assert.Testdata(t, ".svg", svg) + }, + }, + { + name: "target-nested-index2", + run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) { + writeFile(t, dir, "target-nested-index2.d2", `a +layers: { + index: { + b + layers: { + nest1: { + c + scenarios: { + nest2: { + d + } + } + } + } + } +}`) + err := runTestMain(t, ctx, dir, env, "--target", `index.nest1.nest2`, "target-nested-index2.d2", "target-nested-index2.svg") + assert.Success(t, err) + svg := readFile(t, dir, "target-nested-index2.svg") + assert.Testdata(t, ".svg", svg) + }, + }, { name: "multiboard/life", run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) { diff --git a/e2etests-cli/testdata/TestCLI_E2E/target-nested-index.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/target-nested-index.exp.svg new file mode 100644 index 000000000..636e9a4fe --- /dev/null +++ b/e2etests-cli/testdata/TestCLI_E2E/target-nested-index.exp.svg @@ -0,0 +1,95 @@ +d + + + diff --git a/e2etests-cli/testdata/TestCLI_E2E/target-nested-index2.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/target-nested-index2.exp.svg new file mode 100644 index 000000000..185df765b --- /dev/null +++ b/e2etests-cli/testdata/TestCLI_E2E/target-nested-index2.exp.svg @@ -0,0 +1,96 @@ +cd + + + +