Skip to content

Fix delimiter propogation#152

Open
devhl-labs wants to merge 2 commits intoStubbleOrg:masterfrom
devhl-labs:devhl/150-delimiter-propogation
Open

Fix delimiter propogation#152
devhl-labs wants to merge 2 commits intoStubbleOrg:masterfrom
devhl-labs:devhl/150-delimiter-propogation

Conversation

@devhl-labs
Copy link
Copy Markdown

Fix: Delimiter changes not propagated to lambda render callback

Fixes #150

Problem

When a template changes delimiters (e.g. {{=<% %>=}}), the render callback passed to lambdas uses the wrong delimiters to parse the template string it receives. This causes lambda content to be output literally instead of being interpolated.

Root cause

SectionToken.Tags is assigned in EndBlock, which is called during the post-parse squash-and-nest phase — after the full template has been parsed. At that point processor.CurrentTags reflects the final delimiter state, not the state that was active when the section's closing tag was actually encountered. If delimiters changed after a section was closed, the section ended up with the wrong tags, and the render callback (which uses those tags to detect and parse mustache content) would fail to recognise the section's content.

Fix

SectionEndToken now carries a CurrentTags snapshot captured at the moment TryClose is called (i.e. when the closing tag is parsed, while processor.CurrentTags is still correct). EndBlock then uses that snapshot instead of processor.CurrentTags. The same fix is applied to both SectionTagParser and InvertedSectionParser.

Changed files

  • src/Stubble.Core/Tokens/SectionEndToken.cs — added CurrentTags property
  • src/Stubble.Core/Parser/TokenParsers/SectionTagParser.cs — snapshot tags in TryClose; use snapshot in EndBlock
  • src/Stubble.Core/Parser/TokenParsers/InvertedSectionParser.cs — same as above

Tests

Three new tests cover the expected behaviour:

  1. It_Should_Propagate_Delimiter_Changes_To_Lambda_Render_Callback — delimiter changed before a flat section; lambda render must use the changed delimiters.
  2. It_Should_Propagate_Delimiter_Changes_To_Lambda_Render_Callback_Nested — same scenario with a nested property path for the lambda.
  3. It_Should_Use_Correct_Delimiters_In_Lambda_When_Delimiters_Change_After_Section — delimiters change back after the section; this is the test that actually failed before the fix and exercises the exact code path that was broken.

@devhl-labs devhl-labs marked this pull request as ready for review March 29, 2026 20:06
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.

Delimiter does not propagate into lambdas

1 participant