From 7131607ad1d251c790ce566119d647e008972aa5 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 27 May 2014 16:26:24 +0200 Subject: [PATCH] Fix regression in handling github-oauth settings in auth.json --- src/Composer/Json/JsonManipulator.php | 4 ++-- .../Composer/Test/Json/JsonManipulatorTest.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index 5547dbd4b..e7c3e1459 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -125,7 +125,7 @@ class JsonManipulator } $subName = null; - if (false !== strpos($name, '.')) { + if (in_array($mainNode, array('config', 'repositories')) && false !== strpos($name, '.')) { list($name, $subName) = explode('.', $name, 2); } @@ -203,7 +203,7 @@ class JsonManipulator } $subName = null; - if (false !== strpos($name, '.')) { + if (in_array($mainNode, array('config', 'repositories')) && false !== strpos($name, '.')) { list($name, $subName) = explode('.', $name, 2); } diff --git a/tests/Composer/Test/Json/JsonManipulatorTest.php b/tests/Composer/Test/Json/JsonManipulatorTest.php index 31ef70f24..9dd8c653d 100644 --- a/tests/Composer/Test/Json/JsonManipulatorTest.php +++ b/tests/Composer/Test/Json/JsonManipulatorTest.php @@ -735,6 +735,24 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase ', $manipulator->getContents()); } + public function testAddRootSettingDoesNotBreakDots() + { + $manipulator = new JsonManipulator('{ + "github-oauth": { + "github.com": "foo" + } +}'); + + $this->assertTrue($manipulator->addSubNode('github-oauth', 'bar', 'baz')); + $this->assertEquals('{ + "github-oauth": { + "github.com": "foo", + "bar": "baz" + } +} +', $manipulator->getContents()); + } + public function testRemoveConfigSettingCanRemoveSubKeyInHash() { $manipulator = new JsonManipulator('{