Эх сурвалжийг харах

Merge remote-tracking branch 'danieliancu/1.0' into 1.0

Jordi Boggiano 9 жил өмнө
parent
commit
47bba5bd14

+ 2 - 2
src/Composer/Json/JsonManipulator.php

@@ -353,7 +353,7 @@ class JsonManipulator
         if ($this->pregMatch('#[^{\s](\s*)\}$#', $this->contents, $match)) {
         if ($this->pregMatch('#[^{\s](\s*)\}$#', $this->contents, $match)) {
             $this->contents = preg_replace(
             $this->contents = preg_replace(
                 '#'.$match[1].'\}$#',
                 '#'.$match[1].'\}$#',
-                addcslashes(',' . $this->newline . $this->indent . JsonFile::encode($key). ': '. $content . $this->newline . '}', '\\'),
+                addcslashes(',' . $this->newline . $this->indent . JsonFile::encode($key). ': '. $content . $this->newline . '}', '\\$'),
                 $this->contents
                 $this->contents
             );
             );
 
 
@@ -363,7 +363,7 @@ class JsonManipulator
         // append at the end of the file
         // append at the end of the file
         $this->contents = preg_replace(
         $this->contents = preg_replace(
             '#\}$#',
             '#\}$#',
-            addcslashes($this->indent . JsonFile::encode($key). ': '.$content . $this->newline . '}', '\\'),
+            addcslashes($this->indent . JsonFile::encode($key). ': '.$content . $this->newline . '}', '\\$'),
             $this->contents
             $this->contents
         );
         );
 
 

+ 38 - 0
tests/Composer/Test/Json/JsonManipulatorTest.php

@@ -2045,6 +2045,31 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase
 ', $manipulator->getContents());
 ', $manipulator->getContents());
     }
     }
 
 
+    public function testAddMainKeyWithContentHavingDollarSignFollowedByDigit()
+    {
+        $manipulator = new JsonManipulator('{
+    "foo": "bar"
+}');
+        
+        $this->assertTrue($manipulator->addMainKey('bar', '$1baz'));
+        $this->assertEquals('{
+    "foo": "bar",
+    "bar": "$1baz"
+}
+', $manipulator->getContents());
+    }
+
+    public function testAddMainKeyWithContentHavingDollarSignFollowedByDigit2()
+    {
+        $manipulator = new JsonManipulator('{}');
+
+        $this->assertTrue($manipulator->addMainKey('foo', '$1bar'));
+        $this->assertEquals('{
+    "foo": "$1bar"
+}
+', $manipulator->getContents());
+    }
+    
     public function testUpdateMainKey()
     public function testUpdateMainKey()
     {
     {
         $manipulator = new JsonManipulator('{
         $manipulator = new JsonManipulator('{
@@ -2105,6 +2130,19 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase
 ', $manipulator->getContents());
 ', $manipulator->getContents());
     }
     }
 
 
+    public function testUpdateMainKeyWithContentHavingDollarSignFollowedByDigit()
+    {
+        $manipulator = new JsonManipulator('{
+    "foo": "bar"
+}');
+
+        $this->assertTrue($manipulator->addMainKey('foo', '$1bar'));
+        $this->assertEquals('{
+    "foo": "$1bar"
+}
+', $manipulator->getContents());
+    }
+    
     public function testIndentDetection()
     public function testIndentDetection()
     {
     {
         $manipulator = new JsonManipulator('{
         $manipulator = new JsonManipulator('{