From 188b3a35c8d2a2a32a23f18b6b628696cb0eeff6 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 9 Jan 2018 17:29:30 +0100 Subject: [PATCH 1/2] Tweak license deprecation text to handle + more gracefully, fixes #6981 --- src/Composer/Package/Loader/ValidatingArrayLoader.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 68279d539..0713a2fe5 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -125,7 +125,12 @@ class ValidatingArrayLoader implements LoaderInterface foreach ($licenses as $license) { $spdxLicense = $licenseValidator->getLicenseByIdentifier($license); if ($spdxLicense && $spdxLicense[3]) { - if (preg_match('{^[AL]?GPL-[123](\.[01])?\+?$}i', $license)) { + if (preg_match('{^[AL]?GPL-[123](\.[01])?\+$}i', $license)) { + $this->warnings[] = sprintf( + 'License "%s" is a deprecated SPDX license identifier, use "'.str_replace('+', '', $license).'-or-later" instead', + $license + ); + } elseif (preg_match('{^[AL]?GPL-[123](\.[01])?$}i', $license)) { $this->warnings[] = sprintf( 'License "%s" is a deprecated SPDX license identifier, use "'.$license.'-only" or "'.$license.'-or-later" instead', $license From 60106edd324f2297f09baa7d11c0f32ebb700764 Mon Sep 17 00:00:00 2001 From: Tomas Klinkenberg Date: Tue, 9 Jan 2018 16:48:15 +0100 Subject: [PATCH 2/2] Added a test to confirm issue #6994. Added a encapsulated group to the replacement parameter of the `preg_replace` for GitLab in `\Composer\Util\Url::updateDistReference()`. This fixes #6994. --- src/Composer/Util/Url.php | 2 +- tests/Composer/Test/Util/UrlTest.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Composer/Util/Url.php b/src/Composer/Util/Url.php index 2fe68c3f1..f8d4b446d 100644 --- a/src/Composer/Util/Url.php +++ b/src/Composer/Util/Url.php @@ -48,7 +48,7 @@ class Url } elseif (in_array($host, $config->get('github-domains'), true)) { $url = preg_replace('{(/repos/[^/]+/[^/]+/(zip|tar)ball)(?:/.+)?$}i', '$1/'.$ref, $url); } elseif (in_array($host, $config->get('gitlab-domains'), true)) { - $url = preg_replace('{(/api/v[34]/projects/[^/]+/repository/archive\.(?:zip|tar\.gz|tar\.bz2|tar)\?sha=).+$}i', '$1'.$ref, $url); + $url = preg_replace('{(/api/v[34]/projects/[^/]+/repository/archive\.(?:zip|tar\.gz|tar\.bz2|tar)\?sha=).+$}i', '${1}'.$ref, $url); } return $url; diff --git a/tests/Composer/Test/Util/UrlTest.php b/tests/Composer/Test/Util/UrlTest.php index 1a4ccda3b..96e71d10e 100644 --- a/tests/Composer/Test/Util/UrlTest.php +++ b/tests/Composer/Test/Util/UrlTest.php @@ -21,12 +21,12 @@ class UrlTest extends TestCase /** * @dataProvider distRefsProvider */ - public function testUpdateDistReference($url, $expectedUrl, $conf = array()) + public function testUpdateDistReference($url, $expectedUrl, $conf = array(), $ref = 'newref') { $config = new Config(); $config->merge(array('config' => $conf)); - $this->assertSame($expectedUrl, Url::updateDistReference($config, $url, 'newref')); + $this->assertSame($expectedUrl, Url::updateDistReference($config, $url, $ref)); } public static function distRefsProvider() @@ -55,6 +55,7 @@ class UrlTest extends TestCase // gitlab enterprise array('https://mygitlab.com/api/v4/projects/foo%2Fbar/repository/archive.tar.gz?sha=abcd', 'https://mygitlab.com/api/v4/projects/foo%2Fbar/repository/archive.tar.gz?sha=newref', array('gitlab-domains' => array('mygitlab.com'))), array('https://mygitlab.com/api/v3/projects/foo%2Fbar/repository/archive.tar.bz2?sha=abcd', 'https://mygitlab.com/api/v3/projects/foo%2Fbar/repository/archive.tar.bz2?sha=newref', array('gitlab-domains' => array('mygitlab.com'))), + array('https://mygitlab.com/api/v3/projects/foo%2Fbar/repository/archive.tar.bz2?sha=abcd', 'https://mygitlab.com/api/v3/projects/foo%2Fbar/repository/archive.tar.bz2?sha=65', array('gitlab-domains' => array('mygitlab.com')), '65'), ); } }