Fix indent detection in json files when an empty line starts the object
parent
32a479a1e7
commit
fa398e14c7
|
@ -358,7 +358,7 @@ class JsonManipulator
|
||||||
|
|
||||||
protected function detectIndenting()
|
protected function detectIndenting()
|
||||||
{
|
{
|
||||||
if ($this->pregMatch('{^(\s+)"}m', $this->contents, $match)) {
|
if ($this->pregMatch('{^([ \t]+)"}m', $this->contents, $match)) {
|
||||||
$this->indent = $match[1];
|
$this->indent = $match[1];
|
||||||
} else {
|
} else {
|
||||||
$this->indent = ' ';
|
$this->indent = ' ';
|
||||||
|
|
|
@ -1112,6 +1112,28 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase
|
||||||
"foo": "qux"
|
"foo": "qux"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
', $manipulator->getContents());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndentDetection()
|
||||||
|
{
|
||||||
|
$manipulator = new JsonManipulator('{
|
||||||
|
|
||||||
|
"require": {
|
||||||
|
"php": "5.*"
|
||||||
|
}
|
||||||
|
}');
|
||||||
|
|
||||||
|
$this->assertTrue($manipulator->addMainKey('require-dev', array('foo' => 'qux')));
|
||||||
|
$this->assertEquals('{
|
||||||
|
|
||||||
|
"require": {
|
||||||
|
"php": "5.*"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"foo": "qux"
|
||||||
|
}
|
||||||
|
}
|
||||||
', $manipulator->getContents());
|
', $manipulator->getContents());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue