From 921b3a0eba139820716f7aeefb553197c14656d8 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 15 Apr 2015 19:26:48 +0100 Subject: [PATCH] Fix regression with non-SPDX licenses in show command, refs #3885 --- src/Composer/Command/ShowCommand.php | 12 ++++++++---- src/Composer/Util/SpdxLicense.php | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 546b51194..d420ec55d 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -392,11 +392,15 @@ EOT foreach ($licenses as $licenseId) { $license = $spdxLicense->getLicenseByIdentifier($licenseId); // keys: 0 fullname, 1 osi, 2 url - // is license OSI approved? - if ($license[1] === true) { - $out = sprintf('%s (%s) (OSI approved) %s', $license[0], $licenseId, $license[2]); + if (!$license) { + $out = $licenseId; } else { - $out = sprintf('%s (%s) %s', $license[0], $licenseId, $license[2]); + // is license OSI approved? + if ($license[1] === true) { + $out = sprintf('%s (%s) (OSI approved) %s', $license[0], $licenseId, $license[2]); + } else { + $out = sprintf('%s (%s) %s', $license[0], $licenseId, $license[2]); + } } $this->getIO()->write('license : ' . $out); diff --git a/src/Composer/Util/SpdxLicense.php b/src/Composer/Util/SpdxLicense.php index 7d052253a..f52fafd81 100644 --- a/src/Composer/Util/SpdxLicense.php +++ b/src/Composer/Util/SpdxLicense.php @@ -49,10 +49,14 @@ class SpdxLicense * * @param string $identifier * - * @return array + * @return array|false */ public function getLicenseByIdentifier($identifier) { + if (!isset($this->licenses[$identifier])) { + return false; + } + $license = $this->licenses[$identifier]; // add URL for the license text (it's not included in the json)