From fddc37e7409c170df7dd8c0815b4c040f90adacb Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 1 Mar 2016 21:33:35 +0100 Subject: [PATCH] ensure dump indentation to be greather than zero --- src/Symfony/Component/Yaml/Dumper.php | 4 ++++ .../Component/Yaml/Tests/DumperTest.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Symfony/Component/Yaml/Dumper.php b/src/Symfony/Component/Yaml/Dumper.php index 576e622a62ae0..0c6cf3c20998a 100644 --- a/src/Symfony/Component/Yaml/Dumper.php +++ b/src/Symfony/Component/Yaml/Dumper.php @@ -30,6 +30,10 @@ class Dumper */ public function __construct($indentation = 4) { + if ($indentation < 1) { + throw new \InvalidArgumentException('The indentation must be greater than zero.'); + } + $this->indentation = $indentation; } diff --git a/src/Symfony/Component/Yaml/Tests/DumperTest.php b/src/Symfony/Component/Yaml/Tests/DumperTest.php index 8df0a980ca0a8..6c771b175f11b 100644 --- a/src/Symfony/Component/Yaml/Tests/DumperTest.php +++ b/src/Symfony/Component/Yaml/Tests/DumperTest.php @@ -347,6 +347,24 @@ public function testDumpMultiLineStringAsScalarBlock() $this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block.yml'), $this->dumper->dump($data, 3, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK)); } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The indentation must be greater than zero + */ + public function testZeroIndentationInConstructorThrowsException() + { + new Dumper(0); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The indentation must be greater than zero + */ + public function testNegativeIndentationInConstructorThrowsException() + { + new Dumper(-4); + } } class A