Skip to content

fix(ui): preview-PNG data-URL must use template.URL type#90

Merged
strausmann merged 2 commits into
mainfrom
fix/template-preview-url-escape
May 18, 2026
Merged

fix(ui): preview-PNG data-URL must use template.URL type#90
strausmann merged 2 commits into
mainfrom
fix/template-preview-url-escape

Conversation

@strausmann
Copy link
Copy Markdown
Owner

Closes #87. Template-Detail-Page showed instead of preview-PNG because html/template default-escapes in src= attributes. Fix: wrap PreviewURI as . Plus regression test that catches the bug. Refs #22

Go html/template escapes "data:image/png;base64,..." in src= attributes
to "#ZgotmplZ" by default as a security guard against `data:text/html`
XSS vectors. PreviewURI was typed `string` in TemplateDetailData, so
the rendered Template-Detail-Page showed the escape marker instead of
the actual preview PNG.

Wrap the URI value in `template.URL` to mark it as already-safe. The
type is preserved through assignment so both the placeholder SVG path
and the data-URL flow correctly.

Regression test asserts the rendered body contains the data-URL prefix
AND does NOT contain the ZgotmplZ marker. Stub template extended to
render <img src="{{ .PreviewURI }}"> so the test catches the bug.

Closes #87
Refs #22
Copilot AI review requested due to automatic review settings May 18, 2026 07:08
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.09%. Comparing base (d6ba346) to head (562f7c9).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #90   +/-   ##
=======================================
  Coverage   91.09%   91.09%           
=======================================
  Files          71       71           
  Lines        3189     3189           
  Branches      271      271           
=======================================
  Hits         2905     2905           
  Misses        216      216           
  Partials       68       68           
Components Coverage Δ
Printer Backends (transport) 87.50% <ø> (ø)
Printer Models (drivers) 91.42% <ø> (ø)
Services 91.87% <ø> (ø)
REST API 87.04% <ø> (ø)
Pydantic Schemas 100.00% <ø> (ø)
Integration Plugins 100.00% <ø> (ø)
Flag Coverage Δ
backend 91.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6ba346...562f7c9. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the template detail preview rendering issue where Go html/template sanitized PNG data URLs to #ZgotmplZ, and adds regression coverage for the behavior.

Changes:

  • Changes TemplateDetailData.PreviewURI to template.URL.
  • Wraps generated preview data URLs and placeholder paths as trusted template URLs.
  • Updates frontend test stubs and adds a regression test for unescaped preview data URLs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
frontend/internal/handlers/template.go Uses template.URL for preview image sources.
frontend/internal/handlers/template_test.go Adds regression coverage for PNG data URL rendering.
frontend/internal/handlers/base.go Updates test stub template output to include preview image markup.

{{define "templates-content"}}<div id="templates-grid">templates</div>{{end}}`,
"template": `{{define "content"}}<div id="template-detail">template</div>{{end}}
{{define "template-content"}}<div id="template-detail">template</div>{{end}}`,
"template": `{{define "content"}}<div id="template-detail">template<img id="preview-img" src="{{ .PreviewURI }}"></div>{{end}}
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where base64-encoded preview images were being incorrectly sanitized by the Go html/template package, resulting in broken image links. By casting the URI to template.URL, the application now explicitly marks these strings as safe for use in HTML attributes, ensuring the preview renders as expected.

Highlights

  • Type Safety for Preview URLs: Updated the PreviewURI field in TemplateDetailData to use the html/template.URL type, preventing the Go template engine from incorrectly sanitizing base64 data URLs.
  • Template Integration: Added the preview image tag to the template detail page layout to correctly display the rendered preview.
  • Regression Testing: Introduced a new test case to verify that base64-encoded preview images are rendered correctly without being escaped to #ZgotmplZ.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue where base64-encoded preview images were being escaped by the Go html/template engine, resulting in broken image links. The fix involves changing the PreviewURI field type from string to template.URL in the TemplateDetailData struct and updating the frontend templates to include the preview image. A regression test has been added to ensure that data URLs are correctly rendered without being escaped. I have no feedback to provide as there were no review comments to evaluate.

Dependabot PR #89 bumped frontend/go.mod to `go 1.25.0`, but the
Dockerfile builder image was still `golang:1.24-alpine`, breaking
the Docker publish workflow on every PR:

  go: go.mod requires go >= 1.25.0 (running go 1.24.13; GOTOOLCHAIN=local)

Bump the builder image to `golang:1.25-alpine` so it matches the
toolchain version declared in go.mod.

Refs #22
@strausmann strausmann merged commit 0f84976 into main May 18, 2026
19 checks passed
@strausmann strausmann deleted the fix/template-preview-url-escape branch May 18, 2026 08:19
github-actions Bot pushed a commit that referenced this pull request May 19, 2026
## <small>0.6.1 (2026-05-19)</small>

* fix(ui): preview-PNG data-URL must use template.URL type (#90) ([0f84976](0f84976)), closes [#90](#90) [#87](#87) [#22](#22) [#89](#89) [#22](#22)
* docs(api): Phase 7c API-Auth design — 3-scope keys + rate-limit + /admin/api-keys UI (#85) ([8792e84](8792e84)), closes [#85](#85) [#22](#22) [#78](#78) [#85](#85) [#22](#22) [#79](#79) [#22](#22)
* docs(api): Phase 7e Template Layout System v2 — semantic schema + aggregation (#86) ([0bab0c0](0bab0c0)), closes [#86](#86) [#22](#22) [#81](#81) [#22](#22)
* chore(deps): bump the go-minor-and-patch group (#89) ([d6ba346](d6ba346)), closes [#89](#89)

[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Template-Detail-Page preview-PNG wird durch html/template escaped (#ZgotmplZ)

2 participants