Skip to content
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

Return null property values instead of treating them as undefined. #410

Merged
merged 1 commit into from
May 10, 2024

Conversation

vshih
Copy link
Contributor

@vshih vshih commented Feb 8, 2023

Return null property values instead of treating them as undefined.

Null array values already return; this change makes null property values behave the same way. I've added unit tests for both cases.

@vshih vshih changed the title Return null property values instead of treating them as not-present. Return null property values instead of treating them as undefined. Feb 8, 2023
@bobthecow bobthecow merged commit ef5b784 into bobthecow:main May 10, 2024
@bobthecow
Copy link
Owner

I somehow missed this pull request … for a year ☹️

Thanks for the fix. I'm going to add a config option for reverting to the previous behavior, because it's been this way for a long, long time, but I'll get this in the next release!

bobthecow added a commit that referenced this pull request May 10, 2024
Per the Mustache spec, keys of a value higher in the context stack shadow similarly named keys lower in the stack. For example, in the template `{{# foo }}{{ bar }}{{/ foo }}` if the value for `foo` has a method, property, or key named `bar`, it will prevent looking lower in the context stack for a another value named `bar`.

In Mustache.php, setting the value of an array key to null prevents lookups higher in the context stack. The behavior should have been identical for object properties (and ArrayAccess) as well, but a bug in the context lookup logic meant that a property which exists but is set to null would not prevent further context lookup.

This change adds a `buggy_property_shadowing` configuration option to preserve the behavior from Mustache.php <= 2.14.2, to ease the transition to the correct behavior.

See #410
@vshih
Copy link
Contributor Author

vshih commented May 10, 2024

Ha! Much appreciated.

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