Skip to content

Conversation

giautm
Copy link
Contributor

@giautm giautm commented Jan 2, 2025

…iles

Close: #6

Summary by Sourcery

Bug Fixes:

  • Fix incorrect usage of text/template which caused issues with HTML rendering.

Copy link

sourcery-ai bot commented Jan 2, 2025

Reviewer's Guide by Sourcery

This pull request fixes an issue where the text/template package was being used to parse HTML templates. The html/template package is now used instead, which provides better security and prevents potential XSS vulnerabilities.

Sequence diagram showing template parsing with html/template

sequenceDiagram
    participant C as Client
    participant T as Template Parser
    participant H as HTML Output

    C->>T: Request template parsing
    Note over T: Now using html/template
    T->>T: Automatically escape<br/>HTML special characters
    T->>H: Generate safe HTML
    H->>C: Return escaped output
Loading

Class diagram showing template package change

classDiagram
    class Template {
        -fs FileSystem
        +Parse()
        +Execute()
    }
    note for Template "Changed import from text/template to html/template"

    class HTMLTemplate {
        +AutoEscapeHTML
        +PreventXSS
    }

    Template --|> HTMLTemplate : Now uses
Loading

File-Level Changes

Change Details Files
Use html/template instead of text/template
  • Changed import path from text/template to html/template
html_template.go

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@giautm giautm changed the title fix: use html/template instead text/template for parse template f… fix: use html/template instead text/template for parse files Jan 2, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @giautm - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding tests to verify the HTML escaping behavior works as expected
  • It would be helpful to add a brief comment explaining why html/template is preferred over text/template for security reasons
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@giautm
Copy link
Contributor Author

giautm commented Jan 2, 2025

No tests was run?

@cnlangzi
Copy link
Member

cnlangzi commented Jan 2, 2025

@giautm good job. thanks.

re Tests, I have no chance to enable it on github. let me fix it now.

by the way, could you also add this PR on https://github.com/yaitoo/xun/blob/main/CHANGELOG.md#unreleased

@cnlangzi cnlangzi self-assigned this Jan 2, 2025
Copy link
Member

@cnlangzi cnlangzi left a comment

Choose a reason for hiding this comment

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

Excellent PR. thanks @giautm
It will be merged when CHANGELOG.md is updated.

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.28%. Comparing base (260cebf) to head (5ffccb7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main       #7   +/-   ##
=======================================
  Coverage   82.28%   82.28%           
=======================================
  Files          21       21           
  Lines         988      988           
=======================================
  Hits          813      813           
  Misses        138      138           
  Partials       37       37           
Flag Coverage Δ
Unit-Tests 82.28% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@giautm
Copy link
Contributor Author

giautm commented Jan 2, 2025

Excellent PR. thanks @giautm It will be merged when CHANGELOG.md is updated.

Update changelog manually is boring stuff, you can have all changes on the GitHub release. They do generate it automatic for you, also https://goreleaser.com support generate Changelog file too.

Use this button when create new release:

Screenshot 2025-01-02 at 20 21 58

@cnlangzi
Copy link
Member

cnlangzi commented Jan 2, 2025

https://goreleaser.com

I will check it , thanks.

@cnlangzi cnlangzi merged commit e7af653 into yaitoo:main Jan 2, 2025
6 checks passed
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.

use html/template to parse template files
2 participants