-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null value in data causes JavaScript error #28
Comments
Nice! Thanks for this find. Would you mind crafting a failing test within the existing test suite and opening a PR that includes the failing test? Thank you. |
I added a test case and also included a possible fix for you to look over. |
Hooray! Thank you for this work. Merged the PR, added a note on this behavoir in the README, and released a new version. As a side note, I would recommend to set an avatar for your GitHub profile, as then you will appear more professional in your online interactions. Thanks again for your work here. It's little improvements like this that help really solidify Open Source projects! |
Is this still open? |
Should have been closed back in July when that PR was merged. Closing now! |
This error is not fully fixed, which case I have met is: import parse from 'json-templates';
const template = parse('{{a}} {{b}}');
console.log(template({ a: 0, b: 1 })); // '0 1': right
console.log(template({ a: null, b: null })); // null: emmm, maybe ' ' better, but acceptable
console.log(template({ a: null, b: 1 })); // Error: TypeError: Cannot read properties of null (reading 'replace') If not provided the default value, and first variable is |
I found another thing which is not so perfect is the default value will be applied on to
This will cause some logic issue in usage, which I will send another fix PR if needed. |
Oh nice! A PR with tests would be most welcome. Thank you. |
Closed by #45 Feel free to reopen if this comes up again. |
In this codesandbox: https://codesandbox.io/s/adoring-dan-6xw6g
There are two conditions that must be met in order for this error to occur:
It appears that the issue is related to #26 where only undefined values are checked, but not null. Therefore, the defaultValue is not used and a null value is returned in the reduce function, leading to a "Cannot read property 'replace' of null" error in the next iteration of the reduce function because "str" is null.
The text was updated successfully, but these errors were encountered: