From 36282393fdb6218b96da388bb022d8832e6bc899 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 21 Feb 2025 08:42:46 -0800 Subject: [PATCH 1/2] imagebundler: treat octet streams with svg signature as svg mimetypes --- lib/imgbundler/imgbundler.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/imgbundler/imgbundler.go b/lib/imgbundler/imgbundler.go index 2c3bce289..7dbd6268e 100644 --- a/lib/imgbundler/imgbundler.go +++ b/lib/imgbundler/imgbundler.go @@ -166,7 +166,7 @@ func worker(ctx context.Context, l simplelog.Logger, inputPath string, href []by var err error if isRemote { l.Debug(fmt.Sprintf("fetching %s remotely", string(href))) - buf, mimeType, err = httpGet(ctx, html.UnescapeString(string(href))) + buf, mimeType, err = httpGet(ctx, l, html.UnescapeString(string(href))) } else { l.Debug(fmt.Sprintf("reading %s from disk", string(href))) path := html.UnescapeString(string(href)) @@ -181,8 +181,15 @@ func worker(ctx context.Context, l simplelog.Logger, inputPath string, href []by if mimeType == "" { mimeType = sniffMimeType(href, buf, isRemote) + l.Debug(fmt.Sprintf("no mimetype provided - sniffed MIME type for %s: %s", string(href), mimeType)) + } else { + l.Debug(fmt.Sprintf("mimetype provided for %s: %s", string(href), mimeType)) } mimeType = strings.Replace(mimeType, "text/xml", "image/svg+xml", 1) + if mimeType == "application/octet-stream" && bytes.Contains(buf, []byte(" Date: Fri, 21 Feb 2025 08:44:39 -0800 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 ea7e4f2aa..cdc65f746 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -9,3 +9,4 @@ - Compiler: - fixes panic when `sql_shape` shape value had mixed casing [#2349](https://github.com/terrastruct/d2/pull/2349) - fixes support for `center` in `d2-config` [#2360](https://github.com/terrastruct/d2/pull/2360) +- CLI: fetch and render remote images of mimetype octet-stream correctly [#2370](https://github.com/terrastruct/d2/pull/2370)