Repository navigation
[6.x] Fix infinite recursion when evaluating cyclic link fields - #15386
Closed
duncanmcclean wants to merge 1 commit into
Closed
duncanmcclean wants to merge 1 commit into
duncanmcclean wants to merge 1 commit into
Conversation
`AugmentedCollection::toArray()` with evaluation eagerly walked whatever `ArrayableLink::toArray()` returned, so entries whose `link` fields point at each other recursed until the stack overflowed. JSON already represents links shallowly, so evaluated arrays now do the same via `ArrayableLink::toShallowArray()`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TeNvgwke5qBF5vWGVWyXce
Member
Author
|
Closing this one. On reflection, it's breaking: for links that don't form a cycle, A different approach is needed. The nested evaluation happens inside the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request fixes an issue where entries whose
linkfields point at each other (A → B → C → A) would cause infinite recursion when the entry was converted to an array or JSON, eg. viaEntry::toArray(),json_encode($entry)or{{ collection:pages as="menu" }}{{ menu | to_json }}.This was happening because
AugmentedCollection::toArray(), when evaluating, eagerly walks whateverArrayableLink::toArray()returns. That's the full augmented array of the linked entry, which contains its ownlinkfield, and so on until the stack overflows. Even without a cycle, this expanded the whole link graph into the array.This PR fixes it by representing links shallowly in evaluated arrays, matching how they're already represented in JSON since #11375.
ArrayableLinkgains atoShallowArray()method, whichjsonSerialize()now uses too. Deep{{ link:field }}/$link['field']access in templates is unchanged.Fixes #9105