Fix case insensitivity of ‘require’ command
When currently executing the `require` command for a package that is already listed in `require(-dev)`, one must use the exact same, case matching package name as written in `composer.json`. That is, if one changes the case of a character in the package name, the `require` command will add a new entry to `require(-dev)`, instead of updating the existing one. This commit fixes the described behaviour to make it consistent with other commands like `update` that are already case insensitive.pull/6524/head
parent
b50eb26740
commit
d51ef83a43
|
@ -69,11 +69,15 @@ class JsonManipulator
|
||||||
|
|
||||||
$links = $matches['value'];
|
$links = $matches['value'];
|
||||||
|
|
||||||
if (isset($decoded[$type][$package])) {
|
// try to find existing link
|
||||||
|
$packageRegex = str_replace('/', '\\\\?/', preg_quote($package));
|
||||||
|
$regex = '{'.self::$DEFINES.'"(?P<package>'.$packageRegex.')"(\s*:\s*)(?&string)}ix';
|
||||||
|
if ($this->pregMatch($regex, $links, $packageMatches)) {
|
||||||
// update existing link
|
// update existing link
|
||||||
$packageRegex = str_replace('/', '\\\\?/', preg_quote($package));
|
$existingPackage = $packageMatches['package'];
|
||||||
$links = preg_replace_callback('{'.self::$DEFINES.'"'.$packageRegex.'"(?P<separator>\s*:\s*)(?&string)}ix', function ($m) use ($package, $constraint) {
|
$packageRegex = str_replace('/', '\\\\?/', preg_quote($existingPackage));
|
||||||
return JsonFile::encode($package) . $m['separator'] . '"' . $constraint . '"';
|
$links = preg_replace_callback('{'.self::$DEFINES.'"'.$packageRegex.'"(?P<separator>\s*:\s*)(?&string)}ix', function ($m) use ($existingPackage, $constraint) {
|
||||||
|
return JsonFile::encode(str_replace('\\/', '/', $existingPackage)) . $m['separator'] . '"' . $constraint . '"';
|
||||||
}, $links);
|
}, $links);
|
||||||
} else {
|
} else {
|
||||||
if ($this->pregMatch('#^\s*\{\s*\S+.*?(\s*\}\s*)$#s', $links, $match)) {
|
if ($this->pregMatch('#^\s*\{\s*\S+.*?(\s*\}\s*)$#s', $links, $match)) {
|
||||||
|
|
|
@ -107,6 +107,28 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase
|
||||||
"vendor/baz": "qux"
|
"vendor/baz": "qux"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
',
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
array(
|
||||||
|
'{
|
||||||
|
"require":
|
||||||
|
{
|
||||||
|
"foo": "bar",
|
||||||
|
"vendor/baz": "baz"
|
||||||
|
}
|
||||||
|
}',
|
||||||
|
'require',
|
||||||
|
'vEnDoR/bAz',
|
||||||
|
'qux',
|
||||||
|
'{
|
||||||
|
"require":
|
||||||
|
{
|
||||||
|
"foo": "bar",
|
||||||
|
"vendor/baz": "qux"
|
||||||
|
}
|
||||||
|
}
|
||||||
',
|
',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
@ -127,6 +149,26 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase
|
||||||
"vendor/baz": "qux"
|
"vendor/baz": "qux"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'{
|
||||||
|
"require":
|
||||||
|
{
|
||||||
|
"foo": "bar",
|
||||||
|
"vendor\/baz": "baz"
|
||||||
|
}
|
||||||
|
}',
|
||||||
|
'require',
|
||||||
|
'vEnDoR/bAz',
|
||||||
|
'qux',
|
||||||
|
'{
|
||||||
|
"require":
|
||||||
|
{
|
||||||
|
"foo": "bar",
|
||||||
|
"vendor/baz": "qux"
|
||||||
|
}
|
||||||
|
}
|
||||||
',
|
',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
|
Loading…
Reference in New Issue