StubbleOrg / Stubble

Trimmed down {{mustache}} templates in .NET
Other
402 stars 58 forks source link

Variable tags in a partial template can be rendered with extra spaces at the end #36

Closed StarLeafRob closed 5 years ago

StarLeafRob commented 5 years ago

I've come across a bug when rendering partial templates in Stubble.Core Version 1.1.2 If the partial tag is indented, e.g.

<div>
    {{>Body}}
</div>

Then additional spaces can get appended to the end of variable tags that appear in the partial. e.g if Body.mustache is

<a href="{{Url}}">
    My Link
</a>

and the data is

{ "Url": "https://github.com" }

then the output is

<div>
    <a href="https://github.com    ">
        My Link
    </a>
</div>

Note the extra spaces that get rendered at the end of {{Url}}.

See https://github.com/StarLeafRob/StubblePartialBugExample for a program that reproduces this.

If you'd like me to have a go at fixing this, let me know - but I thought I'd report it as an issue first as I'm not very familiar with the Stubble code yet.

Romanx commented 5 years ago

Hi there,

Thanks for opening the issue. This looks to be to do with how we handle the indenting with partial templates. Thank you for the reproduction I should be able to have a test and look at a clean way to handle this shortly.

If you'd like to look at where the issue is occurring then i'd be more than happy to help you contribute a fix.

Thanks!

Romanx commented 5 years ago

Hi @StarLeafRob,

I found some time this weekend to look at this. It seems to be related to the way we try to fold literal tags during parsing when they're next to each other to simplify the rendering. This wasn't taking indenting into account correctly and will now only fold tags that are the same indent level which solves the problem.

Thanks for reporting it and i'll try get a bug fix out for this shortly.

StarLeafRob commented 5 years ago

I see, thank you for the explanation (and the speedy fix) - I was away for a few days after I reported it, but a heroic effort to fix it before I even got a chance to look at it!

Romanx commented 5 years ago

This has now been released in version 1.2 on nuget. Thanks very much for your contribution! 👍