From 7bf83815bdc340d752c0722d305ec6c9f8806a42 Mon Sep 17 00:00:00 2001 From: guiguiboy Date: Sun, 8 Jul 2018 16:43:43 +0200 Subject: [PATCH] Added deprecation notice when mapping keys are found in multi-line blocks --- UPGRADE-4.3.md | 5 +++++ UPGRADE-5.0.md | 6 ++++++ src/Symfony/Component/Yaml/CHANGELOG.md | 5 +++++ src/Symfony/Component/Yaml/Parser.php | 5 +++++ src/Symfony/Component/Yaml/Tests/ParserTest.php | 14 ++++++++++++++ 5 files changed, 35 insertions(+) diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index c2faae90c0b4..062a2ef0aa8b 100644 --- a/UPGRADE-4.3.md +++ b/UPGRADE-4.3.md @@ -30,3 +30,8 @@ HttpFoundation use `Symfony\Component\Mime\FileBinaryMimeTypeGuesser` instead. * The `FileinfoMimeTypeGuesser` class has been deprecated, use `Symfony\Component\Mime\FileinfoMimeTypeGuesser` instead. + +Yaml +---- + + * Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0. diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 7e6703801bfb..8c75ff0d1b3c 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -286,3 +286,9 @@ Workflow * `add` method has been removed use `addWorkflow` method in `Workflow\Registry` instead. * `SupportStrategyInterface` has been removed, use `WorkflowSupportStrategyInterface` instead. * `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead. + +Yaml +---- + + * The parser is now stricter and will throw a `ParseException` when a + mapping is found inside a multi-line string. diff --git a/src/Symfony/Component/Yaml/CHANGELOG.md b/src/Symfony/Component/Yaml/CHANGELOG.md index cfd81fad2701..1bc5561ba3db 100644 --- a/src/Symfony/Component/Yaml/CHANGELOG.md +++ b/src/Symfony/Component/Yaml/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.3.0 +----- + + * Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0. + 4.2.0 ----- diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index d63467084b89..04b00d9870f8 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -390,6 +390,11 @@ private function doParse(string $value, int $flags) if (0 === $this->offset && !$deprecatedUsage && isset($line[0]) && ' ' === $line[0]) { throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename); } + + if (false !== strpos($line, ': ')) { + @trigger_error('Support for mapping keys in multi-line blocks is deprecated since Symfony 4.3 and will throw a ParseException in 5.0.', E_USER_DEPRECATED); + } + if ('' === trim($line)) { $value .= "\n"; } elseif (!$previousLineWasNewline && !$previousLineWasTerminatedWithBackslash) { diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 7e465595caa8..6fc02e1d1f10 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -525,6 +525,20 @@ public function testObjectsSupportDisabledWithExceptions() $this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); } + /** + * @group legacy + * @expectedDeprecation Support for mapping keys in multi-line blocks is deprecated since Symfony 4.3 and will throw a ParseException in 5.0. + */ + public function testMappingKeyInMultiLineStringTriggersDeprecationNotice() + { + $yaml = <<<'EOF' +data: + dbal:wrong + default_connection: monolith +EOF; + $this->parser->parse($yaml); + } + public function testCanParseContentWithTrailingSpaces() { $yaml = "items: \n foo: bar";