diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 7eb081d5d..526a08b78 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -5,3 +5,5 @@ - Composition: links pointing to own board are purged [#2203](https://github.com/terrastruct/d2/pull/2203) #### Bugfixes ⛑️ + +- Imports: fixes using substitutions in `icon` values [#2207](https://github.com/terrastruct/d2/pull/2207) diff --git a/d2ir/compile.go b/d2ir/compile.go index b7e477809..fbd0b00ca 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -984,6 +984,10 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) { } if f.Name == "icon" && f.Primary() != nil { val := f.Primary().Value.ScalarString() + // It's likely a substitution + if val == "" { + continue + } u, err := url.Parse(html.UnescapeString(val)) isRemoteImg := err == nil && strings.HasPrefix(u.Scheme, "http") if isRemoteImg { diff --git a/e2etests-cli/main_test.go b/e2etests-cli/main_test.go index 471ae6b52..432d59aff 100644 --- a/e2etests-cli/main_test.go +++ b/e2etests-cli/main_test.go @@ -821,6 +821,33 @@ a.b.c.d assert.Testdata(t, ".svg", svg) }, }, + { + name: "chain_icon_import", + run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) { + writeFile(t, dir, "hello-world.d2", `...@y +hello.class: Ecs`) + writeFile(t, dir, "y.d2", ` +...@x +classes: { + Ecs: { + shape: "circle" + icon: ${icons.ecs} + } +} +`) + writeFile(t, dir, "x.d2", ` +vars: { + icons: { + ecs: "https://icons.terrastruct.com/aws%2FCompute%2FAmazon-Elastic-Container-Service.svg" + } +} +`) + err := runTestMain(t, ctx, dir, env, filepath.Join(dir, "hello-world.d2")) + assert.Success(t, err) + svg := readFile(t, dir, "hello-world.svg") + assert.Testdata(t, ".svg", svg) + }, + }, { name: "board_import", run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) { diff --git a/e2etests-cli/testdata/TestCLI_E2E/chain_icon_import.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/chain_icon_import.exp.svg new file mode 100644 index 000000000..2f9aa0756 --- /dev/null +++ b/e2etests-cli/testdata/TestCLI_E2E/chain_icon_import.exp.svg @@ -0,0 +1,95 @@ +hello + + +