Repository navigation
Fix JsonManipulator::addSubNode modifying a nested key with the same name - #13109
Merged
Merged
Conversation
…Node The lazy loop over sibling pairs backtracked through every pair when the key was missing, and used a stack frame per sibling when it was present.
…ched Existence now comes from the decoded JSON, so a regex miss no longer appends a duplicate key and PCRE limit errors let callers fall back to a full rewrite.
Member
|
Thanks |
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.
JsonManipulator::addSubNode()(used byaddConfigSetting(),addProperty()and socomposer config) looks for the existing child with a regex that is not anchored to the node's top level. If the same key name appears deeper inside the node first, that nested value gets replaced instead, and the intended top-level key is never added.Reproduction with a
composer.jsoncontaining:{ "extra": { "symfony": { "allow-contrib": true } } }composer config extra.allow-contrib false --jsonturnsextra.symfony.allow-contribintofalseand does not addextra.allow-contrib. LikewiseaddConfigSetting('php', ...)on a file withconfig.platform.phpset overwrites the platform version instead of addingconfig.php.The fix anchors
$childRegexat the opening brace of the node and only allows skipping over complete"key": valuemembers before the target key, so only direct children match. Nested objects are consumed whole by(?&json), so keys inside them can no longer match.Added tests for
addConfigSetting,addSubNodeandaddPropertywith a nested same-name key; they fail without the change.tests/Composer/Test/Jsonpasses and PHPStan reports no errors for the file.Targeting 2.10 since the code is identical there and it's a bug fix; happy to retarget to
mainif preferred.