Fix #1748 where allowed prototype methods are not called#1958
Fix #1748 where allowed prototype methods are not called#1958aalimovs wants to merge 1 commit intohandlebars-lang:4.xfrom
Conversation
|
Note: failing test was not caused by this PR and was fixed in #1963. Needs rebase. |
fa0420e to
b1d1aa8
Compare
|
@jaylinski rebased, but I've no idea why this PR now picks up changes in If you want me to recreate the PR let me know. |
b8f7a6d to
5cae846
Compare
|
No problem, I fixed it. |
|
|
||
| if (resultIsAllowed(result, container.protoAccessControl, propertyName)) { | ||
| if (typeof result === 'function') { | ||
| return parent[propertyName](); |
There was a problem hiding this comment.
Why did you use parent[propertyName]() instead of result()? Any specific reason?
There was a problem hiding this comment.
It doesn't work with result(), complains that:
TypeError: String.prototype.trim called on null or undefined
I'm not 100% sure why, but as I understand result loses this context.
|
This fix isn't right - handlebars.js/lib/handlebars/runtime.js Lines 146 to 148 in f422bfd They are called with the Handlebars context, not with the object preceding the dot as in regular JavaScript. Changing this would be a breaking change, and it's not clear for what benefit. You can create a |
|
I'm still curious why the documentation states that it should work. 🤔 |
|
That was added somewhat recently to the documentation with the security fixes. I think it was just a mistake. |
|
I don't know why I added this example to the docs and did not notice that it does not work. The Handlebars way to solve the issue is to register a "trim" helper and use "{{trim aString}}" instead. |
|
I'll keep this issue open until we corrected the wrong documentation and close it afterwards. |
Fixes #1748 where allowed prototype methods are not called.
Without this fix the official documentation is incorrect:
The result is
[object Object], notabc.