Skip to content

Commit

Permalink
resources/integrity: Return string instead of template.HTMLAttr
Browse files Browse the repository at this point in the history
Closes #11513
  • Loading branch information
jmooring authored and bep committed Oct 2, 2023
1 parent 3af8bde commit 4c95389
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions resources/resource_transformers/integrity/integrity.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/hex"
"fmt"
"hash"
"html/template"
"io"

"github.com/gohugoio/hugo/resources/internal"
Expand Down Expand Up @@ -109,9 +108,9 @@ func (c *Client) Fingerprint(res resources.ResourceTransformer, algo string) (re
return res.Transform(&fingerprintTransformation{algo: algo})
}

func integrity(algo string, sum []byte) template.HTMLAttr {
func integrity(algo string, sum []byte) string {
encoded := base64.StdEncoding.EncodeToString(sum)
return template.HTMLAttr(algo + "-" + encoded)
return algo + "-" + encoded
}

func digest(h hash.Hash) ([]byte, error) {
Expand Down
3 changes: 1 addition & 2 deletions resources/resource_transformers/integrity/integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package integrity

import (
"context"
"html/template"
"testing"

"github.com/gohugoio/hugo/resources/resource"
Expand Down Expand Up @@ -63,7 +62,7 @@ func TestTransform(t *testing.T) {

c.Assert(err, qt.IsNil)
c.Assert(transformed.RelPermalink(), qt.Equals, "/hugo.a5ad1c6961214a55de53c1ce6e60d27b6b761f54851fa65e33066460dfa6a0db.txt")
c.Assert(transformed.Data(), qt.DeepEquals, map[string]any{"Integrity": template.HTMLAttr("sha256-pa0caWEhSlXeU8HObmDSe2t2H1SFH6ZeMwZkYN+moNs=")})
c.Assert(transformed.Data(), qt.DeepEquals, map[string]any{"Integrity": "sha256-pa0caWEhSlXeU8HObmDSe2t2H1SFH6ZeMwZkYN+moNs="})
content, err := transformed.(resource.ContentProvider).Content(context.Background())
c.Assert(err, qt.IsNil)
c.Assert(content, qt.Equals, "Hugo Rocks!")
Expand Down

0 comments on commit 4c95389

Please sign in to comment.