Skip to content

fix: trim whitespace in unescaped (triple mustache) tags#61

Open
Yanhu007 wants to merge 1 commit into
hoisie:masterfrom
Yanhu007:fix/unescaped-tag-whitespace
Open

fix: trim whitespace in unescaped (triple mustache) tags#61
Yanhu007 wants to merge 1 commit into
hoisie:masterfrom
Yanhu007:fix/unescaped-tag-whitespace

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #51

Problem

Unescaped tags with spaces around the variable name fail to resolve:

// Works:
tmpl, _ := mustache.ParseString("{{{String}}}")
tmpl.Render(map[string]string{"String": "<b>hi</b>"})
// → "<b>hi</b>"

// Broken (returns empty):
tmpl, _ := mustache.ParseString("{{{ String }}}")
tmpl.Render(map[string]string{"String": "<b>hi</b>"})
// → ""

The tag extraction for {{{...}}} strips the outer braces via tag[1:len(tag)-1] but doesn't trim the resulting whitespace, leaving the tag name as String instead of String.

Fix

Apply strings.TrimSpace after extracting the inner tag name, matching the behavior of other tag types (which already use TrimSpace during initial tag extraction).

All existing tests pass.

{{{ String }}} with spaces around the tag name did not match data
keys because the extracted tag name retained leading/trailing
whitespace. Only {{{String}}} without spaces worked.

Apply strings.TrimSpace to the extracted tag name in both
top-level and section-level unescaped tag parsing.

Fixes hoisie#51
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.

Unescaped replace only works without spaces in tag

1 participant