Browse Source

Fix regression in handling github-oauth settings in auth.json

Jordi Boggiano 10 years ago
parent
commit
7131607ad1

+ 2 - 2
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);
         }
 

+ 18 - 0
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('{