From e87190e3da7758023cbcb7c7f4e63530e3866884 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 21 Nov 2015 02:35:00 +0000 Subject: [PATCH] Detect duplicate keys in composer.json, fixes #4620 --- composer.json | 2 +- composer.lock | 16 ++++++++-------- src/Composer/Factory.php | 9 +++++++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 4d2c34828..a743d278a 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "justinrainbow/json-schema": "^1.4.4", "composer/spdx-licenses": "^1.0", "composer/semver": "^1.0", - "seld/jsonlint": "^1.0", + "seld/jsonlint": "^1.4", "symfony/console": "^2.5 || ^3.0", "symfony/finder": "^2.2 || ^3.0", "symfony/process": "^2.1 || ^3.0", diff --git a/composer.lock b/composer.lock index 6a45f6ec2..4c485958a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "c88bd0dc7f99b674776d931973d3e1b7", - "content-hash": "e31b609879971d42d37f09bb6a526192", + "hash": "93e6b0b69e1d2831beb016b291320e65", + "content-hash": "e50c021dd9230b14ee88fe3d62c3923f", "packages": [ { "name": "composer/semver", @@ -246,20 +246,20 @@ }, { "name": "seld/jsonlint", - "version": "1.3.1", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "863ae85c6d3ef60ca49cb12bd051c4a0648c40c4" + "reference": "66834d3e3566bb5798db7294619388786ae99394" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/863ae85c6d3ef60ca49cb12bd051c4a0648c40c4", - "reference": "863ae85c6d3ef60ca49cb12bd051c4a0648c40c4", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/66834d3e3566bb5798db7294619388786ae99394", + "reference": "66834d3e3566bb5798db7294619388786ae99394", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": "^5.3 || ^7.0" }, "bin": [ "bin/jsonlint" @@ -288,7 +288,7 @@ "parser", "validator" ], - "time": "2015-01-04 21:18:15" + "time": "2015-11-21 02:21:41" }, { "name": "seld/phar-utils", diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 898db2355..f85266b8b 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -25,6 +25,7 @@ use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Composer\EventDispatcher\EventDispatcher; use Composer\Autoload\AutoloadGenerator; use Composer\Semver\VersionParser; +use Seld\JsonLint\JsonParser; /** * Creates a configured instance of composer. @@ -219,6 +220,14 @@ class Factory } $file->validateSchema(JsonFile::LAX_SCHEMA); + $jsonParser = new JsonParser; + try { + $jsonParser->parse(file_get_contents($localConfig), JsonParser::DETECT_KEY_CONFLICTS); + } catch (\Seld\JsonLint\DuplicateKeyException $e) { + $details = $e->getDetails(); + $io->writeError('Key '.$details['key'].' is a duplicate in '.$localConfig.' at line '.$details['line'].''); + } + $localConfig = $file->read(); }