Fix HTML entities displaying incorrectly in PDF exports
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix HTML entities displaying incorrectly in PDF exports (e.g., "&" showing as "&")
|
||||||
|
|
||||||
## [0.78.0] - 2025-10-23
|
## [0.78.0] - 2025-10-23
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -92,14 +92,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func RenderHTML(data DocumentData) ([]byte, error) {
|
func RenderHTML(data DocumentData) ([]byte, error) {
|
||||||
data.Title = html.EscapeString(data.Title)
|
|
||||||
data.Approver = html.EscapeString(data.Approver)
|
|
||||||
data.Description = html.EscapeString(data.Description)
|
|
||||||
|
|
||||||
for i := range data.Signatures {
|
|
||||||
data.Signatures[i].SignedBy = html.EscapeString(data.Signatures[i].SignedBy)
|
|
||||||
}
|
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if err := documentTemplate.Execute(&buf, data); err != nil {
|
if err := documentTemplate.Execute(&buf, data); err != nil {
|
||||||
return nil, fmt.Errorf("failed to execute template: %w", err)
|
return nil, fmt.Errorf("failed to execute template: %w", err)
|
||||||
|
|||||||
@@ -77,9 +77,9 @@ func TestRenderHTML(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantContains: []string{
|
wantContains: []string{
|
||||||
"Test &amp; &lt;Script&gt; Title",
|
"Test & <Script> Title",
|
||||||
"John &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt; Doe",
|
"John <script>alert('xss')</script> Doe",
|
||||||
"Alice &amp; &lt;Bob&gt;",
|
"Alice & <Bob>",
|
||||||
},
|
},
|
||||||
wantNotContains: []string{
|
wantNotContains: []string{
|
||||||
"<script>alert('xss')</script>",
|
"<script>alert('xss')</script>",
|
||||||
@@ -266,12 +266,12 @@ func TestHTMLEscaping(t *testing.T) {
|
|||||||
|
|
||||||
resultStr := string(result)
|
resultStr := string(result)
|
||||||
|
|
||||||
// Verify dangerous content is escaped
|
// Verify dangerous content is escaped
|
||||||
assert.NotContains(t, resultStr, "<script>alert('xss')</script>")
|
assert.NotContains(t, resultStr, "<script>alert('xss')</script>")
|
||||||
assert.NotContains(t, resultStr, "<malicious>tag")
|
assert.NotContains(t, resultStr, "<malicious>tag")
|
||||||
assert.Contains(t, resultStr, "&lt;script&gt;")
|
assert.Contains(t, resultStr, "<script>")
|
||||||
assert.Contains(t, resultStr, "&amp;")
|
assert.Contains(t, resultStr, "&")
|
||||||
assert.Contains(t, resultStr, "&#39;")
|
assert.Contains(t, resultStr, "'")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarkdownRendering(t *testing.T) {
|
func TestMarkdownRendering(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user