From 817c9684ce2be22f71c01e312f08dce0d7d42efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Mon, 8 Dec 2025 17:11:20 +0100 Subject: [PATCH] fix: Include scale into the hash Should fix https://github.com/kovetskiy/mark/issues/683 --- d2/d2.go | 11 ++++++++++- d2/d2_test.go | 2 +- mermaid/mermaid.go | 10 +++++++++- mermaid/mermaid_test.go | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/d2/d2.go b/d2/d2.go index d6b85fc..aa2dc89 100644 --- a/d2/d2.go +++ b/d2/d2.go @@ -4,7 +4,9 @@ import ( "bytes" "context" "encoding/base64" + "encoding/binary" "fmt" + "math" "strconv" "time" @@ -63,7 +65,14 @@ func ProcessD2(title string, d2Diagram []byte, scale float64) (attachment.Attach return attachment.Attachment{}, err } - checkSum, err := attachment.GetChecksum(bytes.NewReader(d2Diagram)) + scaleAsBytes := make([]byte, 8) + + binary.LittleEndian.PutUint64(scaleAsBytes, math.Float64bits(scale)) + + d2Bytes := append(d2Diagram, scaleAsBytes...) + + checkSum, err := attachment.GetChecksum(bytes.NewReader(d2Bytes)) + log.Debugf(nil, "Checksum: %q -> %s", title, checkSum) if err != nil { diff --git a/d2/d2_test.go b/d2/d2_test.go index 043129f..2a50080 100644 --- a/d2/d2_test.go +++ b/d2/d2_test.go @@ -75,7 +75,7 @@ func TestExtractD2Image(t *testing.T) { Filename: "example.png", Name: "example", Replace: "example", - Checksum: "58fa387384181445e2d8f90a8c7fda945cb75174f73e8b9853ff59b9e0103ddd", + Checksum: "40e75f93e09da9242d4b1ab8e2892665ec7d5bd1ac78a4b65210ee219cf62297", ID: "", Width: "198", Height: "441", diff --git a/mermaid/mermaid.go b/mermaid/mermaid.go index 8fa8b08..80cea1c 100644 --- a/mermaid/mermaid.go +++ b/mermaid/mermaid.go @@ -3,6 +3,8 @@ package mermaid import ( "bytes" "context" + "encoding/binary" + "math" "strconv" "time" @@ -30,7 +32,13 @@ func ProcessMermaidLocally(title string, mermaidDiagram []byte, scale float64) ( return attachment.Attachment{}, err } - checkSum, err := attachment.GetChecksum(bytes.NewReader(mermaidDiagram)) + scaleAsBytes := make([]byte, 8) + + binary.LittleEndian.PutUint64(scaleAsBytes, math.Float64bits(scale)) + + mermaidBytes := append(mermaidDiagram, scaleAsBytes...) + + checkSum, err := attachment.GetChecksum(bytes.NewReader(mermaidBytes)) log.Debugf(nil, "Checksum: %q -> %s", title, checkSum) if err != nil { diff --git a/mermaid/mermaid_test.go b/mermaid/mermaid_test.go index db087ed..9e87ad3 100644 --- a/mermaid/mermaid_test.go +++ b/mermaid/mermaid_test.go @@ -22,7 +22,7 @@ func TestExtractMermaidImage(t *testing.T) { Filename: "example.png", Name: "example", Replace: "example", - Checksum: "1743a4f31ab66244591f06c8056e08053b8e0a554eb9a38709af6e9d145ac84f", + Checksum: "26296b73c960c25850b37bc9dd77cb24fce1a78db83b37755a25af7f8a48cc96", ID: "", Width: "87", Height: "174",