Repository navigation
Keep empty link and repositories keys unless a removal emptied them - #13178
Merged
Merged
Conversation
An empty "require-dev" key was removed when requiring a package, so the next "composer require --dev" added it at the end of composer.json. The key is now removed only when moving packages out of it emptied it.
nicolas-grekas
added a commit
to symfony/flex
that referenced
this pull request
Oct 29, 2026
…ions in composer.json and composer.lock (nicolas-grekas) This PR was squashed before being merged into the 2.x branch. Discussion ---------- Fix unpacking packs on Composer < 2.2.6 and keep empty sections in composer.json and composer.lock | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Three fixes found while looking at #783 again. They all touch `Unpacker::updateLock()`, one commit each. Unpacking a pack removed the empty `require-dev` section of composer.json, even with `composer update`. `unpack()` already removes the packs from composer.json, so I removed the second removal. `composer require` removes the empty section too: that part of #783 is fixed in composer/composer#13178. Unpacking failed with a fatal error on Composer < 2.2.6, because `getDevMode()` doesn't exist there. Updating composer.lock turned the empty `stability-flags`, `platform` and `platform-dev` objects into arrays, and the next `composer update` turned them back. Flex now keeps them as objects, like Composer's `Locker` does. Commits ------- a07d27b Fix unpacking packs on Composer < 2.2.6 and keep empty sections in composer.json and composer.lock
Add JsonManipulator::removeLink(), which removes the key only when that removal emptied it, and use it in RequireCommand and JsonConfigSource::removeLink() (remove command, plugins). removeRepository() now also keeps an already empty "repositories" key. This also drops the extra read of composer.json in RequireCommand, avoids count() on a non-array key in its fallback path, and adds tests for the fallback path.
API Surface ChangesIf any of the additions below are not intended as public API, mark them with New API SurfaceMethods
|
The fallback in RequireCommand::updateFile now reuses the empty object coercion from JsonConfigSource, so keys like "config": {} are no longer rewritten as arrays, and it writes to the JsonFile it was given. The fallback test now asserts the manipulator actually fails.
Member
|
Thanks, updated a few more paths so hopefully we have decent coverage of these edge cases now |
gemmaro
pushed a commit
to phpusers-ja/composer
that referenced
this pull request
Nov 9, 2026
…omposer#13178) Co-authored-by: Jordi Boggiano <[email protected]>
mwalbeck
pushed a commit
to mwalbeck/docker-composer
that referenced
this pull request
Nov 22, 2026
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [composer/composer](https://github.com/composer/composer) | minor | `2.10.3` → `2.11.2` | --- ### Release Notes <details> <summary>composer/composer (composer/composer)</summary> ### [`v2.11.2`](https://github.com/composer/composer/blob/HEAD/CHANGELOG.md#2112-2026-11-11) [Compare Source](composer/composer@2.11.1...2.11.2) - Security: Fixed arbitrary command execution via the `prevent_url_access_callable` transport option being loaded from `composer.lock` / `vendor/composer/installed.json` (GHSA-jhfp-4ppm-crmm) - Security: Fixed malicious zip archives being able to write files outside of the package directory via symlinked entries when extraction falls back from `unzip` to `ZipArchive` (GHSA-w6hj-6587-3jh5) - Security: Fixed inline repository HTTP credentials being sent to dist mirrors on other hosts supplied by a crafted `composer.lock` / `vendor/composer/installed.json` (GHSA-x82q-x274-r6pq) - Security: Updated the bundled symfony/filesystem to a version fixing a disclosed vulnerability present in the one shipped with 2.11.1 (GHSA-6prc-h956-hxjq) - Security: Fixed `Authorization` and `Cookie` headers set in request options, e.g. via a repository's `http.header` option, being resent when following a redirect to another origin ([#​13253](composer/composer#13253)) - Security: Fixed non-auth config settings being read from a project's `auth.json` and the `COMPOSER_AUTH` env var, and `home` being read from a project's composer.json, these are now ignored with a warning ([#​13208](composer/composer#13208)) - Security: Fixed IPs blocked by the `prevent_ip_access_callable` transport option only being rejected after the request had been sent, and rejected in-flight downloads not being stopped ([#​13255](composer/composer#13255)) - Added `exclude-branches` option to VCS repositories to skip branches matching the given patterns, e.g. bot-managed ones ([#​13235](composer/composer#13235)) - Added support for setting `allow-git-fallback` to `false` in GitLab, Bitbucket and Forgejo repositories to fail on API errors instead of falling back to a git clone ([#​13234](composer/composer#13234)) - Added a 30 seconds stall timeout so downloads from a server which accepts the connection but never responds are aborted and retried instead of hanging for 300 seconds, configurable or disabled via the `COMPOSER_HTTP_STALL_TIMEOUT` env var ([#​13243](composer/composer#13243)) - Improved performance of security advisory lookups by querying the API only once per package name ([#​13202](composer/composer#13202)) - Improved performance of VCS repository updates by skipping the default branch lookup when the git mirror is up to date ([#​13224](composer/composer#13224)) - Improved performance and memory usage of dependency resolution, package loading and sorting, and repository traversal ([#​13187](composer/composer#13187), [#​13188](composer/composer#13188), [#​13194](composer/composer#13194), [#​13197](composer/composer#13197), [#​13200](composer/composer#13200), [#​13211](composer/composer#13211), [#​13217](composer/composer#13217), [#​13218](composer/composer#13218)) - Improved performance with micro-optimizations in path and URL handling, lock file and `installed.php` generation, archiving and TLS/HTTP helpers ([#​13189](composer/composer#13189), [#​13190](composer/composer#13190), [#​13191](composer/composer#13191), [#​13192](composer/composer#13192), [#​13193](composer/composer#13193), [#​13195](composer/composer#13195), [#​13196](composer/composer#13196), [#​13198](composer/composer#13198), [#​13214](composer/composer#13214), [#​13215](composer/composer#13215), [#​13216](composer/composer#13216), [#​13220](composer/composer#13220), [#​13222](composer/composer#13222)) - Fixed `config` failing with a schema error or corrupting composer.json by turning nested `{}` into `[]` when adding or removing dotted sub-keys ([#​13210](composer/composer#13210)) - Fixed `config --unset`, `remove` and `require` leaving in place or duplicating composer.json keys which are set to `null` ([#​13225](composer/composer#13225)) - Fixed dist URLs of codeberg.org packages and bitbucket zip archives not being updated when requiring a specific commit with `dev-branch#hash` ([#​13242](composer/composer#13242)) - Fixed an undefined array key warning hiding the real error when curl 8.23+ fails to parse a URL ([#​13252](composer/composer#13252)) ### [`v2.11.1`](https://github.com/composer/composer/blob/HEAD/CHANGELOG.md#2111-2026-10-30) [Compare Source](composer/composer@2.11.0...2.11.1) - Added a warning when the cache dir is on a Windows drive while running in WSL, as this makes filesystem operations very slow ([#​13175](composer/composer#13175)) - Fixed GitLab CI job tokens failing to authenticate against the GitLab Composer package registry, which requires HTTP Basic auth rather than the `JOB-TOKEN` header ([#​13180](composer/composer#13180)) - Fixed every update aborting with a `SecurityException` when a PHP extension reports a name that is not a valid platform package name ([#​13184](composer/composer#13184)) - Fixed `require` and `remove` dropping empty `require`/`require-dev`/`repositories` keys from composer.json when the command had not emptied them itself ([#​13178](composer/composer#13178)) - Fixed a PHP 8.6 deprecation warning from composer/ca-bundle ([`8bf8c27`](composer/composer@8bf8c27)) - Fixed invalid `custom-headers` auth entries being sent as-is, they are now ignored with a warning ([#​13181](composer/composer#13181)) ### [`v2.11.0`](https://github.com/composer/composer/blob/HEAD/CHANGELOG.md#2110-2026-10-29) [Compare Source](composer/composer@2.10.3...2.11.0) - Security: Fixed package names in `vendor/composer/installed.json` being able to escape the vendor directory during install and reinstall (GHSA-c968-33g3-wh7p) - Security: Fixed inline repository HTTP headers, such as API tokens, being written into `composer.lock` (GHSA-fm2w-xgf2-f9fh) - Security: Fixed additional arguments passed to `@composer` scripts not being escaped ([#​13169](composer/composer#13169)) - Security: Fixed svn passwords not being redacted from debug output ([#​13171](composer/composer#13171)) - Security: Sanitize URL-embedded credentials in hg and fossil error output ([#​13172](composer/composer#13172)) - Improved dependency resolution performance and memory usage ([#​13174](composer/composer#13174)) - Fixed `config` corrupting composer.json when modifying `extra` or `scripts` entries which are JSON arrays ([#​13167](composer/composer#13167)) - Fixed archives not being unwrapped correctly when OS/editor metadata entries like `__MACOSX` or `Thumbs.db` sit next to the package's top-level dir ([#​13168](composer/composer#13168)) - Fixed `@script` references with quoted arguments being split on spaces when passed to `@composer` scripts ([#​13169](composer/composer#13169)) </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNjAuMCIsInVwZGF0ZWRJblZlciI6IjQzLjI2MC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Reviewed-on: https://git.walbeck.it/mwalbeck/docker-composer/pulls/1165
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.
When composer.json contains an empty
"require-dev": {},composer require fooremoves the key, even though no package was moved out ofrequire-dev. The nextcomposer require --dev barthen addsrequire-devat the end of the file. The Symfony skeleton ships an emptyrequire-devright afterrequirefor this reason.This PR removes a key only when the removal itself emptied it, which is the case of #9462. An already empty key is kept. This applies to:
composer requiremoving packages betweenrequireandrequire-dev(both directions)ConfigSourceInterface::removeLink(), used bycomposer removeand pluginscomposer repo remove,composer config --unset repositories.foo): an already emptyrepositorieskey is kept when the repository isn't thereJsonManipulator::removeLink()is added for this, andRequireCommanduses it instead of re-reading composer.json.The fallback path in
RequireCommand::updateFile(used when the clean edit fails) now also:JsonConfigSource, so keys like"config": {}are no longer rewritten as[]JsonFileit was given instead of$this->jsoncount()on a key that may not be an arrayIt is covered by a test that checks it gives the same result as the clean path.