Skip to content

Commit 54bca3f

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: Add missing RFC comment ensure dump indentation to be greather than zero
2 parents d6a189b + 81b59b9 commit 54bca3f

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class Response
171171
428 => 'Precondition Required', // RFC6585
172172
429 => 'Too Many Requests', // RFC6585
173173
431 => 'Request Header Fields Too Large', // RFC6585
174-
451 => 'Unavailable For Legal Reasons',
174+
451 => 'Unavailable For Legal Reasons', // RFC7725
175175
500 => 'Internal Server Error',
176176
501 => 'Not Implemented',
177177
502 => 'Bad Gateway',

src/Symfony/Component/Yaml/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

src/Symfony/Component/Yaml/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

src/Symfony/Component/Yaml/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
}

src/Symfony/Component/Yaml/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)