Skip to content

Compile failing when partial is an instance of Handlebars.SafeString#1054

Closed
raiden-dev wants to merge 1 commit intohandlebars-lang:masterfrom
raiden-dev:master
Closed

Compile failing when partial is an instance of Handlebars.SafeString#1054
raiden-dev wants to merge 1 commit intohandlebars-lang:masterfrom
raiden-dev:master

Conversation

@raiden-dev
Copy link
Copy Markdown

When partial's indent option is used, runtime compilation of string partial is failing for partials produced by Handlebars.SafeString because of split method call.

let lines = result.split('\n');

https://github.com/wycats/handlebars.js/blob/master/lib/handlebars/runtime.js#L52

See jsfiddle demo for details.

I have fixed it in a straight way by explicitly calling result.toString().

@kpdecker
Copy link
Copy Markdown
Collaborator

Can you add a test to ensure that this does not regress and I'll be glad to
add. spec/regressions.js might be a good place to add this, otherwise
spec/partials.js

On Tue, Jul 7, 2015 at 8:05 PM Andrey Kravtsov [email protected]
wrote:

When partial's indent option is used, runtime compilation of string
partial is failing for partials produced by Handlebars.SafeString because
of split method call.

let lines = result.split('\n');

https://github.com/wycats/handlebars.js/blob/2c1d509c6cafea145ece5ff9bc8b5c2ca98f9749/lib/handlebars/runtime.js#L52

See jsfiddle demo http://jsfiddle.net/j1j60b0u/ for details.

I have fixed it in a straight way by implicitly calling result.toString().

You can view, comment on, or merge this pull request online at:

#1054
Commit Summary

  • Ensure that partial invoke result is a string before splitting it
    for indenting

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#1054.

@raiden-dev
Copy link
Copy Markdown
Author

I'm little bit unsure about exact solution to this problem. Should partial always return a string only?
If so it'll be better to call result.toString() inside invokePartial and not in the any conditions later, e.g. one in invokePartialWrapper.
Could you tell me about partial's main concept? Is it just a part of the template (and in that case it should always return string), or partial in Handlebars is something more than just a piece of template (and maybe it should return objects like SafeString in some cases)?

@kpdecker
Copy link
Copy Markdown
Collaborator

You raise an interesting point. I was surprised that you were able to cause a safe string return from a partial in the first place. Modifying your example a little bit, http://jsfiddle.net/j1j60b0u/1/, shows that a template with a simple wrapper can return a SafeString as well, which could lead to issues down the road. I think we need to make sure that the return from any template, partial or not, is always a string and have proper tests to ensure that :)

@kpdecker kpdecker added this to the Next milestone Aug 3, 2015
@kpdecker kpdecker closed this in 8e868ab Aug 3, 2015
@kpdecker
Copy link
Copy Markdown
Collaborator

kpdecker commented Aug 3, 2015

@RD5, I went the route of consistent string return from the API and implemented your test case there. Thanks for the report!

@raiden-dev
Copy link
Copy Markdown
Author

Thank you!

flenter pushed a commit to flenter/handlebars.js that referenced this pull request Aug 27, 2015
Certain optimizations for simple templates could result in objects returned by helpers returned rather than their string representation, resulting in some odd edge cases. This ensures that strings are always returned from the API for consistency.

Fixes handlebars-lang#1054.
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.

2 participants