Skip to content

Commit

Permalink
Merge pull request #2207 from alixander/import-icon-bug
Browse files Browse the repository at this point in the history
d2ir: fix icon substitutions
  • Loading branch information
alixander authored Nov 11, 2024
2 parents 95a0b94 + ef35bfb commit b2ce591
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions e2etests-cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
95 changes: 95 additions & 0 deletions e2etests-cli/testdata/TestCLI_E2E/chain_icon_import.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b2ce591

Please sign in to comment.