Skip to content

Commit

Permalink
feature #27898 [Yaml] Fixed invalid Parser behavior (guiguiboy)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Yaml] Fixed invalid Parser behavior

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27874
| License       | MIT
| Doc PR        | NA

This fixes #27874
I'm not sure about the update in composer.json though. It seems a good idea because I was able to run composer update without the zip extension. If required, I'll remove it.

Commits
-------

7bf8381 Added deprecation notice when mapping keys are found in multi-line blocks
  • Loading branch information
xabbuh committed Feb 6, 2019
2 parents 2cad97b + 7bf8381 commit 974cab3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions UPGRADE-4.3.md
Expand Up @@ -44,3 +44,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.
6 changes: 6 additions & 0 deletions UPGRADE-5.0.md
Expand Up @@ -291,3 +291,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.
5 changes: 5 additions & 0 deletions 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
-----

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Expand Up @@ -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";
Expand Down

0 comments on commit 974cab3

Please sign in to comment.