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

Fix: Do not sort allow-plugins configuration #590

Merged
merged 2 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ For a full diff see [`1.0.3...main`][1.0.3...main].
### Fixed

- Updated `justinrainbow/json-schema` ([#517]), by [@dependabot]
- Stopped sorting the newly added `allow-plugins` configuration ([#590]), by [@dependabot]

## [`1.0.3`][1.0.3]

Expand Down Expand Up @@ -425,6 +426,7 @@ For a full diff see [`5d8b3e2...0.1.0`][5d8b3e2...0.1.0].
[#564]: https://github.com/ergebnis/json-normalizer/pull/564
[#573]: https://github.com/ergebnis/json-normalizer/pull/573
[#589]: https://github.com/ergebnis/json-normalizer/pull/589
[#590]: https://github.com/ergebnis/json-normalizer/pull/590

[@BackEndTea]: https://github.com/BackEndTea
[@dependabot]: https://github.com/dependabot
Expand Down
2 changes: 2 additions & 0 deletions src/Vendor/Composer/ConfigHashNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ final class ConfigHashNormalizer implements NormalizerInterface
];

/**
* @see https://getcomposer.org/doc/06-config.md#allow-plugins
* @see https://getcomposer.org/doc/06-config.md#preferred-install
*/
private const PROPERTY_PATHS_THAT_SHOULD_NOT_BE_SORTED = [
'config.allow-plugins',
'config.preferred-install',
];

Expand Down
81 changes: 81 additions & 0 deletions test/Unit/Vendor/Composer/ConfigHashNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,87 @@ public function testNormalizeSortsConfigHashRecursivelyIfPropertyExists(string $
self::assertJsonStringEqualsJsonStringNormalized($expected->encoded(), $normalized->encoded());
}

/**
* @see https://getcomposer.org/doc/06-config.md#allow-plugins
*/
public function testNormalizeDoesNotSortAllowPluginsInConfig(): void
{
$json = Json::fromEncoded(
<<<'JSON'
{
"config": {
"sort-packages": true,
"allow-plugins": {
"foo/*": true,
"bar/*": false,
"*": true
}
}
}
JSON
);

$expected = Json::fromEncoded(
<<<'JSON'
{
"config": {
"allow-plugins": {
"foo/*": true,
"bar/*": false,
"*": true
},
"sort-packages": true
}
}
JSON
);

$normalizer = new Vendor\Composer\ConfigHashNormalizer();

$normalized = $normalizer->normalize($json);

self::assertJsonStringEqualsJsonStringNormalized($expected->encoded(), $normalized->encoded());
}

public function testNormalizeSortsAllowPluginsInOtherProperty(): void
{
$json = Json::fromEncoded(
<<<'JSON'
{
"extra": {
"something": {
"allowed-plugins": {
"foo": true,
"bar": false
}
}
}
}
JSON
);

$expected = Json::fromEncoded(
<<<'JSON'
{
"extra": {
"something": {
"allowed-plugins": {
"bar": false,
"foo": true
}
}
}
}
JSON
);

$normalizer = new Vendor\Composer\ConfigHashNormalizer();

$normalized = $normalizer->normalize($json);

self::assertJsonStringEqualsJsonStringNormalized($expected->encoded(), $normalized->encoded());
}

/**
* @see https://github.com/ergebnis/composer-normalize/issues/644
* @see https://getcomposer.org/doc/06-config.md#preferred-install
Expand Down