Skip to content

Commit 5cbb480

Browse files
bug #717 [COMPOSER] Fix strpos(): Empty needle when using bash variables (symfonyaml)
This PR was squashed before being merged into the 1.9-dev branch. Discussion ---------- [COMPOSER] Fix strpos(): Empty needle when using bash variables **Context** I discovered this issue from a personal specific script, when a bash variable was not set properly. I get this PHP error from flex: ``` [ErrorException] strpos(): Empty needle ``` **How to reproduce** ``` symfony new test --version=lts cd test composer require symfony/yaml:$VERSION ``` Commits ------- 8ecdcb9 [COMPOSER] Fix strpos(): Empty needle when using bash variables
2 parents 26dd8a6 + 8ecdcb9 commit 5cbb480

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/PackageResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private function throwAlternatives(string $argument, int $position)
119119
$alternatives = [];
120120
foreach (self::$aliases as $alias => $package) {
121121
$lev = levenshtein($argument, $alias);
122-
if ($lev <= \strlen($argument) / 3 || false !== strpos($alias, $argument)) {
122+
if ($lev <= \strlen($argument) / 3 || ('' !== $argument && false !== strpos($alias, $argument))) {
123123
$alternatives[$package][] = $alias;
124124
}
125125
}

tests/PackageResolverTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,14 @@ public function getWrongPackages()
7979
['cli', '2.3', 'consale'],
8080
"\"consale\" is not a valid alias. Did you mean this:\n \"symfony/console\", supported aliases: \"console\"",
8181
],
82-
8382
[
8483
['qwerty'],
8584
'"qwerty" is not a valid alias.',
8685
],
86+
[
87+
['lts:'],
88+
'Could not parse version constraint "".',
89+
],
8790
];
8891
}
8992

0 commit comments

Comments
 (0)