Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Delimiter changes not propagated to lambda render callback
Fixes #150
Problem
When a template changes delimiters (e.g.
{{=<% %>=}}), therendercallback 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.Tagsis assigned inEndBlock, which is called during the post-parse squash-and-nest phase — after the full template has been parsed. At that pointprocessor.CurrentTagsreflects 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 therendercallback (which uses those tags to detect and parse mustache content) would fail to recognise the section's content.Fix
SectionEndTokennow carries aCurrentTagssnapshot captured at the momentTryCloseis called (i.e. when the closing tag is parsed, whileprocessor.CurrentTagsis still correct).EndBlockthen uses that snapshot instead ofprocessor.CurrentTags. The same fix is applied to bothSectionTagParserandInvertedSectionParser.Changed files
src/Stubble.Core/Tokens/SectionEndToken.cs— addedCurrentTagspropertysrc/Stubble.Core/Parser/TokenParsers/SectionTagParser.cs— snapshot tags inTryClose; use snapshot inEndBlocksrc/Stubble.Core/Parser/TokenParsers/InvertedSectionParser.cs— same as aboveTests
Three new tests cover the expected behaviour:
It_Should_Propagate_Delimiter_Changes_To_Lambda_Render_Callback— delimiter changed before a flat section; lambdarendermust use the changed delimiters.It_Should_Propagate_Delimiter_Changes_To_Lambda_Render_Callback_Nested— same scenario with a nested property path for the lambda.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.