Skip to content

Commit 6122202

Browse files
committed
Prevent reading further into aliased/dev versions
- Read up to the end of the version and normalize just the version - Fix tests
1 parent dc7aacf commit 6122202

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

src/Parser/InstallOutputParser.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function parse(array $output): array
4848

4949
// Parse action
5050
if (!preg_match(
51-
'/^\- ([A-Z][a-z]+) ([a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*) \(([^\)\s]+)\)/i',
51+
'/^\- ([A-Z][a-z]+) ([a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*) \(([^\=)]+)( => ([^\)]+))?\)/i',
5252
$line,
5353
$matches
5454
)) {
@@ -57,17 +57,23 @@ public function parse(array $output): array
5757

5858
$action = strtolower($matches[1]);
5959
$package = $matches[2];
60-
$version = $matches[6];
60+
$version = trim($matches[6]);
61+
if (strpos($version, ' ') !== false) {
62+
$version = explode(' ', $version)[0];
63+
}
64+
$newVersion = isset($matches[8]) ? trim($matches[8]) : null;
65+
if (isset($newVersion) && strpos($newVersion, ' ') !== false) {
66+
$newVersion = explode(' ', $newVersion)[0];
67+
}
6168

6269
if ($section === 'lock') {
6370
switch ($action) {
6471
case 'locking':
6572
$lockFile['locked'][$package] = $parser->normalize($version);
6673
break;
6774
case 'upgrading':
68-
[$oldVersion, $newVersion] = explode(' => ', $version);
6975
$lockFile['upgraded'][$package] = [
70-
$parser->normalize($oldVersion),
76+
$parser->normalize($version),
7177
$parser->normalize($newVersion)
7278
];
7379
break;
@@ -81,9 +87,8 @@ public function parse(array $output): array
8187
$packages['installed'][$package] = $parser->normalize($version);
8288
break;
8389
case 'upgrading':
84-
[$oldVersion, $newVersion] = explode(' => ', $version);
8590
$packages['upgraded'][$package] = [
86-
$parser->normalize($oldVersion),
91+
$parser->normalize($version),
8792
$parser->normalize($newVersion)
8893
];
8994
break;

tests/Cases/Commands/InstallTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function itCanRunAnInstallMocked(): void
5050

5151
// Check a couple of packages in the lock file
5252
$this->assertArrayHasKey('winter/storm', $install->getLockInstalled());
53-
$this->assertEquals('dev-develop 0a729ee', $install->getLockInstalled()['winter/storm']);
53+
$this->assertEquals('dev-develop', $install->getLockInstalled()['winter/storm']);
5454

5555
$this->assertArrayHasKey('symfony/yaml', $install->getLockInstalled());
5656
$this->assertEquals('3.4.47.0', $install->getLockInstalled()['symfony/yaml']);
@@ -61,9 +61,12 @@ public function itCanRunAnInstallMocked(): void
6161
$this->assertArrayHasKey('league/flysystem', $install->getLockInstalled());
6262
$this->assertEquals('1.1.3.0', $install->getLockInstalled()['league/flysystem']);
6363

64+
$this->assertArrayHasKey('nesbot/carbon', $install->getLockInstalled());
65+
$this->assertEquals('2.48.9999999.9999999-dev', $install->getLockInstalled()['nesbot/carbon']);
66+
6467
// Check a couple of packages
6568
$this->assertArrayHasKey('winter/storm', $install->getInstalled());
66-
$this->assertEquals('dev-develop 0a729ee', $install->getInstalled()['winter/storm']);
69+
$this->assertEquals('dev-develop', $install->getInstalled()['winter/storm']);
6770

6871
$this->assertArrayHasKey('symfony/yaml', $install->getInstalled());
6972
$this->assertEquals('3.4.47.0', $install->getInstalled()['symfony/yaml']);
@@ -73,6 +76,12 @@ public function itCanRunAnInstallMocked(): void
7376

7477
$this->assertArrayHasKey('league/flysystem', $install->getInstalled());
7578
$this->assertEquals('1.1.3.0', $install->getInstalled()['league/flysystem']);
79+
80+
$this->assertArrayHasKey('league/flysystem', $install->getInstalled());
81+
$this->assertEquals('1.1.3.0', $install->getInstalled()['league/flysystem']);
82+
83+
$this->assertArrayHasKey('nesbot/carbon', $install->getInstalled());
84+
$this->assertEquals('2.48.9999999.9999999-dev', $install->getInstalled()['nesbot/carbon']);
7685
}
7786

7887
/**

tests/Cases/Commands/SearchTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function itCanRunAMockedSearch(): void
7878
*/
7979
public function itCanRunRealSearch(): void
8080
{
81-
$search = $this->composer->search('winter', 'winter-module');
81+
$search = $this->composer->search('winter/', 'winter-module');
8282

8383
$this->assertArraySubset([
8484
[

tests/Cases/Commands/UpdateTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function itCanRunAnUpdateMocked()
5151

5252
// Check a couple of packages in the lock file
5353
$this->assertArrayHasKey('winter/storm', $update->getLockInstalled());
54-
$this->assertEquals('dev-develop 0a729ee', $update->getLockInstalled()['winter/storm']);
54+
$this->assertEquals('dev-develop', $update->getLockInstalled()['winter/storm']);
5555

5656
$this->assertArrayHasKey('symfony/yaml', $update->getLockInstalled());
5757
$this->assertEquals('3.4.47.0', $update->getLockInstalled()['symfony/yaml']);
@@ -64,7 +64,7 @@ public function itCanRunAnUpdateMocked()
6464

6565
// Check a couple of packages
6666
$this->assertArrayHasKey('winter/storm', $update->getInstalled());
67-
$this->assertEquals('dev-develop 0a729ee', $update->getInstalled()['winter/storm']);
67+
$this->assertEquals('dev-develop', $update->getInstalled()['winter/storm']);
6868

6969
$this->assertArrayHasKey('symfony/yaml', $update->getInstalled());
7070
$this->assertEquals('3.4.47.0', $update->getInstalled()['symfony/yaml']);
@@ -103,7 +103,7 @@ public function itCanRunAnUpdateLockFileOnlyMocked()
103103

104104
// Check a couple of packages
105105
$this->assertArrayHasKey('winter/storm', $update->getLockInstalled());
106-
$this->assertEquals('dev-develop 0a729ee', $update->getLockInstalled()['winter/storm']);
106+
$this->assertEquals('dev-develop', $update->getLockInstalled()['winter/storm']);
107107

108108
$this->assertArrayHasKey('symfony/yaml', $update->getLockInstalled());
109109
$this->assertEquals('3.4.47.0', $update->getLockInstalled()['symfony/yaml']);

tests/fixtures/valid/validCleanUpdate/output.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Lock file operations: 106 installs, 0 updates, 0 removals
2727
- Locking mockery/mockery (1.4.3)
2828
- Locking monolog/monolog (2.2.0)
2929
- Locking myclabs/deep-copy (1.10.2)
30-
- Locking nesbot/carbon (2.48.1)
30+
- Locking nesbot/carbon (2.48.x-dev 08f4bbf)
3131
- Locking nikic/php-parser (v4.10.5)
3232
- Locking opis/closure (3.6.2)
3333
- Locking paragonie/random_compat (v2.0.20)
@@ -131,7 +131,7 @@ Package operations: 106 installs, 0 updates, 0 removals
131131
- Downloading symfony/css-selector (v5.3.0)
132132
- Downloading symfony/yaml (v3.4.47)
133133
- Downloading scssphp/scssphp (v1.5.2)
134-
- Downloading nesbot/carbon (2.48.1)
134+
- Downloading nesbot/carbon (2.48.x-dev 08f4bbf)
135135
- Syncing winter/storm (dev-develop 0a729ee) into cache
136136
- Syncing winter/wn-backend-module (dev-develop 2f45d5a) into cache
137137
- Syncing winter/wn-cms-module (dev-develop 33fd0a1) into cache
@@ -230,7 +230,7 @@ Package operations: 106 installs, 0 updates, 0 removals
230230
- Installing twig/twig (v2.14.6): Extracting archive
231231
- Installing symfony/yaml (v3.4.47): Extracting archive
232232
- Installing scssphp/scssphp (v1.5.2): Extracting archive
233-
- Installing nesbot/carbon (2.48.1): Extracting archive
233+
- Installing nesbot/carbon (2.48.x-dev 08f4bbf): Extracting archive
234234
- Installing linkorb/jsmin-php (1.0.0): Extracting archive
235235
- Installing league/csv (9.7.1): Extracting archive
236236
- Installing laravel/framework (v6.20.27): Extracting archive

0 commit comments

Comments
 (0)