Skip to content

fix: apply TrimBlocks once per template - #388

Open
SashaMIT wants to merge 1 commit into
flosch:release/v6from
SashaMIT:fix/trim-blocks-once
Open

SashaMIT wants to merge 1 commit into
flosch:release/v6from
SashaMIT:fix/trim-blocks-once

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Oct 9, 2026

Copy link
Copy Markdown

Summary

TrimBlocks and LStripBlocks rewrite the template tokens. Execute did that on every call, so a cached template lost another newline on the second render.

The trim now runs once. The first render is still a\nb\n\nc\n. The second render stays the same.

Fixes #386.

Test plan

  • go test -count=1 -run TestIssue386 . failed before the change (second render "a\nb\nc\n", first render "a\nb\n\nc\n") and passes after it
  • go test -count=1 . passes
  • go test -race -count=1 -run TestIssue386 . passes

Executing a template twice dropped another newline because TrimBlocks rewrote the shared tokens on every render.
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

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.

1 participant