From c366dd8a4294de910b484d6a75f20e5b95f5ab59 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 12 Apr 2025 02:14:33 -0700 Subject: [PATCH 1/2] d2ir: fix error handling for composite glob filter --- d2compiler/compile_test.go | 12 ++++++++++++ d2ir/compile.go | 2 +- .../TestCompile/composite-glob-filter.exp.json | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 testdata/d2compiler/TestCompile/composite-glob-filter.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 44c4d1bb2..702295099 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1714,6 +1714,18 @@ steps: { assert.Equal(t, 1, len(g.Layers[0].Steps)) }, }, + { + name: "composite-glob-filter", + + text: ` +*: { + &shape: [a; b] +} +k +`, + expErr: `d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites +d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites`, + }, { name: "import-nested-var", diff --git a/d2ir/compile.go b/d2ir/compile.go index 04754ce48..91c0739e8 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -796,7 +796,7 @@ func (c *compiler) ampersandFilter(refctx *RefContext) bool { return false } if len(fa) == 0 { - if refctx.Key.Value.ScalarBox().Unbox().ScalarString() == "*" { + if refctx.Key.Value.ScalarBox().Unbox() != nil && refctx.Key.Value.ScalarBox().Unbox().ScalarString() == "*" { return false } // The field/edge has no value for this filter diff --git a/testdata/d2compiler/TestCompile/composite-glob-filter.exp.json b/testdata/d2compiler/TestCompile/composite-glob-filter.exp.json new file mode 100644 index 000000000..f7cc9c42a --- /dev/null +++ b/testdata/d2compiler/TestCompile/composite-glob-filter.exp.json @@ -0,0 +1,15 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2,2:2:8-2:16:22", + "errmsg": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites" + }, + { + "range": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2,2:2:8-2:16:22", + "errmsg": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites" + } + ] + } +} From 84fcab4adf316a6f9f20fda7f44b73b08c426c43 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 12 Apr 2025 02:15:33 -0700 Subject: [PATCH 2/2] next --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 2d814312d..794f22164 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -36,6 +36,7 @@ - fixes inconsistencies when objects were double quoted [#2390](https://github.com/terrastruct/d2/pull/2390) - fixes globs not applying to spread substitutions [#2426](https://github.com/terrastruct/d2/issues/2426) - fixes panic when classes were mixed with layers incorrectly [#2448](https://github.com/terrastruct/d2/pull/2448) + - fixes panic using glob ampersand filters with composite values [#2489](https://github.com/terrastruct/d2/pull/2489) - Formatter: - fixes substitutions in quotes surrounded by text [#2462](https://github.com/terrastruct/d2/pull/2462) - CLI: fetch and render remote images of mimetype octet-stream correctly [#2370](https://github.com/terrastruct/d2/pull/2370)