10000 feature #27898 [Yaml] Fixed invalid Parser behavior (guiguiboy) · symfony/symfony@974cab3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 974cab3

Browse files
committed
feature #27898 [Yaml] Fixed invalid Parser behavior (guiguiboy)
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
2 parents 2cad97b + 7bf8381 commit 974cab3

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

UPGRADE-4.3.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ HttpFoundation
4444
use `Symfony\Component\Mime\FileBinaryMimeTypeGuesser` instead.
4545
* The `FileinfoMimeTypeGuesser` class has been deprecated,
4646
use `Symfony\Component\Mime\FileinfoMimeTypeGuesser` instead.
47+
48+
Yaml
49+
----
50+
51+
* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.

UPGRADE-5.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,9 @@ Workflow
291291
* `add` method has been removed use `addWorkflow` method in `Workflow\Registry` instead.
292292
* `SupportStrategyInterface` has been removed, use `WorkflowSupportStrategyInterface` instead.
293293
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
294+
295+
Yaml
296+
----
297+
298+
* The parser is now stricter and will throw a `ParseException` when a
299+
mapping is found inside a multi-line string.

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.
8+
49
4.2.0
510
-----
611

src/Symfony/Component/Yaml/Parser.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ private function doParse(string $value, int $flags)
390390
< 10A3E span class=pl-k>if (0 === $this->offset && !$deprecatedUsage && isset($line[0]) && ' ' === $line[0]) {
391391
throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
392392
}
393+
394+
if (false !== strpos($line, ': ')) {
395+
@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);
396+
}
397+
393398
if ('' === trim($line)) {
394399
$value .= "\n";
395400
} elseif (!$previousLineWasNewline && !$previousLineWasTerminatedWithBackslash) {

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,20 @@ public function testObjectsSupportDisabledWithExceptions()
525525
$this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
526526
}
527527

528+
/**
529+
* @group legacy
530+
* @expectedDeprecation Support for mapping keys in multi-line blocks is deprecated since Symfony 4.3 and will throw a ParseException in 5.0.
531+
*/
532+
public function testMappingKeyInMultiLineStringTriggersDeprecationNotice()
533+
{
534+
$yaml = <<<'EOF'
535+
data:
536+
dbal:wrong
537+
default_connection: monolith
538+
EOF;
539+
$this->parser->parse($yaml);
540+
}
541+
528542
public function testCanParseContentWithTrailingSpaces()
529543
{
530544
$yaml = "items: \n foo: bar";

0 commit comments

Comments
 (0)
0