Skip to content

Commit f5c746c

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Form] [ChoiceType] Prefer placeholder to empty_value Add missing RFC comment ensure dump indentation to be greather than zero
2 parents 2a4ee40 + 9f492c4 commit f5c746c

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

Dumper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class Dumper
3232
*/
3333
public function setIndentation($num)
3434
{
35+
if ($num < 1) {
36+
throw new \InvalidArgumentException('The indentation must be greater than zero.');
37+
}
38+
3539
$this->indentation = (int) $num;
3640
}
3741

Tests/DumperTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,24 @@ public function getEscapeSequences()
228228
'paragraph-separator' => array("\t\\P", '"\t\\\\P"'),
229229
);
230230
}
231+
232+
/**
233+
* @expectedException \InvalidArgumentException
234+
* @expectedExceptionMessage The indentation must be greater than zero
235+
*/
236+
public function testZeroIndentationThrowsException()
237+
{
238+
$this->dumper->setIndentation(0);
239+
}
240+
241+
/**
242+
* @expectedException \InvalidArgumentException
243+
* @expectedExceptionMessage The indentation must be greater than zero
244+
*/
245+
public function testNegativeIndentationThrowsException()
246+
{
247+
$this->dumper->setIndentation(-4);
248+
}
231249
}
232250

233251
class A

Tests/YamlTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,22 @@ public function testLegacyParseFromFile()
3434
$parsedByContents = Yaml::parse($contents);
3535
$this->assertEquals($parsedByFilename, $parsedByContents);
3636
}
37+
38+
/**
39+
* @expectedException \InvalidArgumentException
40+
* @expectedExceptionMessage The indentation must be greater than zero
41+
*/
42+
public function testZeroIndentationThrowsException()
43+
{
44+
Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, 0);
45+
}
46+
47+
/**
48+
* @expectedException \InvalidArgumentException
49+
* @expectedExceptionMessage The indentation must be greater than zero
50+
*/
51+
public function testNegativeIndentationThrowsException()
52+
{
53+
Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, -4);
54+
}
3755
}

Yaml.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public static function parse($input, $exceptionOnInvalidType = false, $objectSup
8888
*/
8989
public static function dump($array, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false)
9090
{
91+
if ($indent < 1) {
92+
throw new \InvalidArgumentException('The indentation must be greater than zero.');
93+
}
94+
9195
$yaml = new Dumper();
9296
$yaml->setIndentation($indent);
9397

0 commit comments

Comments
 (0)