From 3d953384fa3d4fd211cbc4f650b5a7a5d984cc6e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 11 Apr 2013 10:34:26 +0200 Subject: [PATCH] Fix indenting detection in JsonManipulator, fixes #1788 --- src/Composer/Json/JsonManipulator.php | 2 +- .../Test/Json/JsonManipulatorTest.php | 34 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index d6b259126..604384c97 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -283,7 +283,7 @@ class JsonManipulator protected function detectIndenting() { - if (preg_match('{^(\s+)"}', $this->contents, $match)) { + if (preg_match('{^(\s+)"}m', $this->contents, $match)) { $this->indent = $match[1]; } else { $this->indent = ' '; diff --git a/tests/Composer/Test/Json/JsonManipulatorTest.php b/tests/Composer/Test/Json/JsonManipulatorTest.php index 4f3a91093..6f23e92f1 100644 --- a/tests/Composer/Test/Json/JsonManipulatorTest.php +++ b/tests/Composer/Test/Json/JsonManipulatorTest.php @@ -311,37 +311,37 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase public function testAddRepositoryCanInitializeEmptyRepositories() { $manipulator = new JsonManipulator('{ - "repositories": { - } + "repositories": { + } }'); $this->assertTrue($manipulator->addRepository('bar', array('type' => 'composer'))); $this->assertEquals('{ - "repositories": { - "bar": { - "type": "composer" - } + "repositories": { + "bar": { + "type": "composer" } + } } ', $manipulator->getContents()); } public function testAddRepositoryCanInitializeFromScratch() { - $manipulator = new JsonManipulator('{ - "a": "b" -}'); + $manipulator = new JsonManipulator("{ +\t\"a\": \"b\" +}"); $this->assertTrue($manipulator->addRepository('bar2', array('type' => 'composer'))); - $this->assertEquals('{ - "a": "b", - "repositories": { - "bar2": { - "type": "composer" - } - } + $this->assertEquals("{ +\t\"a\": \"b\", +\t\"repositories\": { +\t\t\"bar2\": { +\t\t\t\"type\": \"composer\" +\t\t} +\t} } -', $manipulator->getContents()); +", $manipulator->getContents()); } public function testAddRepositoryCanAdd()