1
0
Fork 0

Merge branch '1.4'

pull/6578/merge
Jordi Boggiano 2017-08-07 10:04:46 +02:00
commit 65d49bf811
2 changed files with 50 additions and 4 deletions

View File

@ -69,11 +69,15 @@ class JsonManipulator
$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
$packageRegex = str_replace('/', '\\\\?/', preg_quote($package));
$links = preg_replace_callback('{'.self::$DEFINES.'"'.$packageRegex.'"(?P<separator>\s*:\s*)(?&string)}ix', function ($m) use ($package, $constraint) {
return JsonFile::encode($package) . $m['separator'] . '"' . $constraint . '"';
$existingPackage = $packageMatches['package'];
$packageRegex = str_replace('/', '\\\\?/', preg_quote($existingPackage));
$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);
} else {
if ($this->pregMatch('#^\s*\{\s*\S+.*?(\s*\}\s*)$#s', $links, $match)) {

View File

@ -107,6 +107,28 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase
"vendor/baz": "qux"
}
}
',
),
array(
'{
"require":
{
"foo": "bar",
"vendor/baz": "baz"
}
}',
'require',
'vEnDoR/bAz',
'qux',
'{
"require":
{
"foo": "bar",
"vendor/baz": "qux"
}
}
',
),
array(
@ -127,6 +149,26 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase
"vendor/baz": "qux"
}
}
',
),
array(
'{
"require":
{
"foo": "bar",
"vendor\/baz": "baz"
}
}',
'require',
'vEnDoR/bAz',
'qux',
'{
"require":
{
"foo": "bar",
"vendor/baz": "qux"
}
}
',
),
array(