From b0c50518b3c324d88cb4d1a1c3403c60a3fb83f8 Mon Sep 17 00:00:00 2001 From: "Jonas L." Date: Thu, 25 Sep 2025 12:40:35 +0200 Subject: [PATCH] fix: no html escaping for changelog template (#277) --- internal/changelog/changelog.go | 2 +- internal/changelog/changelog_test.go | 25 ++++---------------- internal/testdata/changelog-entry-prefix.txt | 19 +++++++++++++++ internal/testdata/changelog-entry-suffix.txt | 9 +++++++ internal/testdata/description-overrides.txt | 2 +- internal/testdata/description-suffix.txt | 2 +- internal/testdata/suffix.txt | 2 +- 7 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 internal/testdata/changelog-entry-prefix.txt create mode 100644 internal/testdata/changelog-entry-suffix.txt diff --git a/internal/changelog/changelog.go b/internal/changelog/changelog.go index d6386b8..dda751a 100644 --- a/internal/changelog/changelog.go +++ b/internal/changelog/changelog.go @@ -3,9 +3,9 @@ package changelog import ( "bytes" _ "embed" - "html/template" "log" "log/slog" + "text/template" "github.com/apricote/releaser-pleaser/internal/commitparser" "github.com/apricote/releaser-pleaser/internal/markdown" diff --git a/internal/changelog/changelog_test.go b/internal/changelog/changelog_test.go index e4fe52f..c2bbf71 100644 --- a/internal/changelog/changelog_test.go +++ b/internal/changelog/changelog_test.go @@ -8,6 +8,7 @@ import ( "github.com/apricote/releaser-pleaser/internal/commitparser" "github.com/apricote/releaser-pleaser/internal/git" + "github.com/apricote/releaser-pleaser/internal/testdata" ) func ptr[T any](input T) *T { @@ -143,16 +144,9 @@ func Test_NewChangelogEntry(t *testing.T) { }, version: "1.0.0", link: "https://example.com/1.0.0", - prefix: "### Breaking Changes", + prefix: testdata.MustReadFileString(t, "prefix.txt"), }, - want: `## [1.0.0](https://example.com/1.0.0) - -### Breaking Changes - -### Bug Fixes - -- Foobar! -`, + want: testdata.MustReadFileString(t, "changelog-entry-prefix.txt"), wantErr: assert.NoError, }, { @@ -167,18 +161,9 @@ func Test_NewChangelogEntry(t *testing.T) { }, version: "1.0.0", link: "https://example.com/1.0.0", - suffix: "### Compatibility\n\nThis version is compatible with flux-compensator v2.2 - v2.9.", + suffix: testdata.MustReadFileString(t, "suffix.txt"), }, - want: `## [1.0.0](https://example.com/1.0.0) - -### Bug Fixes - -- Foobar! - -### Compatibility - -This version is compatible with flux-compensator v2.2 - v2.9. -`, + want: testdata.MustReadFileString(t, "changelog-entry-suffix.txt"), wantErr: assert.NoError, }, } diff --git a/internal/testdata/changelog-entry-prefix.txt b/internal/testdata/changelog-entry-prefix.txt new file mode 100644 index 0000000..186d04a --- /dev/null +++ b/internal/testdata/changelog-entry-prefix.txt @@ -0,0 +1,19 @@ +## [1.0.0](https://example.com/1.0.0) + +## Foo + +- Cool thing + +```go +// Some code example +func IsPositive(number int) error { + if number < 0 { + return fmt.Errorf("number %d is negative", number) + } + return nil +} +``` + +### Bug Fixes + +- Foobar! diff --git a/internal/testdata/changelog-entry-suffix.txt b/internal/testdata/changelog-entry-suffix.txt new file mode 100644 index 0000000..91bbb05 --- /dev/null +++ b/internal/testdata/changelog-entry-suffix.txt @@ -0,0 +1,9 @@ +## [1.0.0](https://example.com/1.0.0) + +### Bug Fixes + +- Foobar! + +## Compatibility + +This version is compatible with flux-compensator v2.2 - v2.9. diff --git a/internal/testdata/description-overrides.txt b/internal/testdata/description-overrides.txt index 2fb8249..5a1db7e 100644 --- a/internal/testdata/description-overrides.txt +++ b/internal/testdata/description-overrides.txt @@ -38,7 +38,7 @@ This will be added to the end of the release notes. ~~~~rp-suffix ## Compatibility -No compatibility guarantees. +This version is compatible with flux-compensator v2.2 - v2.9. ~~~~ diff --git a/internal/testdata/description-suffix.txt b/internal/testdata/description-suffix.txt index 4ce7f3b..d0a1596 100644 --- a/internal/testdata/description-suffix.txt +++ b/internal/testdata/description-suffix.txt @@ -25,7 +25,7 @@ This will be added to the end of the release notes. ~~~~rp-suffix ## Compatibility -No compatibility guarantees. +This version is compatible with flux-compensator v2.2 - v2.9. ~~~~ diff --git a/internal/testdata/suffix.txt b/internal/testdata/suffix.txt index b8d35c0..3fc6656 100644 --- a/internal/testdata/suffix.txt +++ b/internal/testdata/suffix.txt @@ -1,3 +1,3 @@ ## Compatibility -No compatibility guarantees. \ No newline at end of file +This version is compatible with flux-compensator v2.2 - v2.9. \ No newline at end of file