Skip to content

Commit d709af0

Browse files
committed
Revert "feature symfony#48022 [Yaml] Fix Yaml Parser with quote end in a new line (maxbeckers)"
This reverts commit 40a2cfb, reversing changes made to d2d36b5.
1 parent f9bdfb2 commit d709af0

File tree

2 files changed

+0
-108
lines changed

2 files changed

+0
-108
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,8 @@ private function getNextEmbedBlock(?int $indentation = null, bool $inSequence =
597597
}
598598

599599
$data = [];
600-
$isInMultiLineQuote = false;
601600

602601
if ($this->getCurrentLineIndentation() >= $newIndent) {
603-
if ($this->isCurrentLineMultiLineQuoteStart()) {
604-
$isInMultiLineQuote = true;
605-
}
606602
$data[] = substr($this->currentLine, $newIndent ?? 0);
607603
} elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {
608604
$data[] = $this->currentLine;
@@ -639,16 +635,6 @@ private function getNextEmbedBlock(?int $indentation = null, bool $inSequence =
639635
if ($this->isCurrentLineBlank()) {
640636
$data[] = substr($this->currentLine, $newIndent);
641637
continue;
642-
} elseif (!$isInMultiLineQuote && $this->isCurrentLineMultiLineQuoteStart()) {
643-
$isInMultiLineQuote = true;
644-
$data[] = substr($this->currentLine, $newIndent);
645-
continue;
646-
} elseif ($isInMultiLineQuote) {
647-
$data[] = $this->currentLine;
648-
if ("'" === (rtrim($this->currentLine)[-1] ?? '')) {
649-
$isInMultiLineQuote = false;
650-
}
651-
continue;
652638
}
653639

654640
if ($indent >= $newIndent) {
@@ -979,49 +965,6 @@ private function isCurrentLineLastLineInDocument(): bool
979965
return ($this->offset + $this->currentLineNb) >= ($this->totalNumberOfLines - 1);
980966
}
981967

982-
/**
983-
* Returns true if the current line is the beginning of a multiline quoted block.
984-
*/
985-
private function isCurrentLineMultiLineQuoteStart(): bool
986-
{
987-
$trimmedLine = trim($this->currentLine);
988-
$trimmedLineLength = \strlen($trimmedLine);
989-
$quoteCount = 0;
990-
$value = '';
991-
// check if the key is quoted
992-
for ($i = 0; $i < $trimmedLineLength; ++$i) {
993-
$char = $trimmedLine[$i];
994-
if ("'" === $char) {
995-
++$quoteCount;
996-
} elseif (':' === $char && 0 === $quoteCount % 2 && ($i === $trimmedLineLength - 1 || ' ' === $trimmedLine[$i + 1])) {
997-
// key and value are separated by the first colon after the (quoted) key followed by a space or linebreak
998-
$value = trim(substr($trimmedLine, ++$i), ' ');
999-
break;
1000-
}
1001-
}
1002-
1003-
if (0 !== strpos($value, "'")) {
1004-
return false;
1005-
}
1006-
1007-
$lineEndQuoteCount = 0;
1008-
for ($i = \strlen($value) - 1; $i > 0; --$i) {
1009-
$char = $value[$i];
1010-
if ("'" === $char) {
1011-
++$lineEndQuoteCount;
1012-
} else {
1013-
break;
1014-
}
1015-
}
1016-
1017-
return 0 === $lineEndQuoteCount % 2;
1018-
}
1019-
1020-
/**
1021-
* Cleanups a YAML string to be parsed.
1022-
*
1023-
* @param string $value The input YAML string
1024-
*/
1025968
private function cleanup(string $value): string
1026969
{
1027970
$value = str_replace(["\r\n", "\r"], "\n", $value);

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

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Yaml\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Yaml\Exception\ParseException;
1615
use Symfony\Component\Yaml\Yaml;
1716

1817
class YamlTest extends TestCase
@@ -25,56 +24,6 @@ public function testParseAndDump()
2524
$this->assertEquals($data, $parsed);
2625
}
2726

28-
public function testParseWithMultilineQuotes()
29-
{
30-
$yaml = <<<YAML
31-
foo:
32-
bar: 'baz
33-
biz
34-
35-
'
36-
baz: 'Lorem
37-
38-
ipsum'
39-
error: Une erreur s'est produite.
40-
trialMode: 'période d''essai'
41-
double_line: 'Les utilisateurs sélectionnés
42-
n''ont pas d''email.
43-
44-
'
45-
a: 'b''
46-
c'
47-
empty: ''
48-
foo:bar: 'foobar'
49-
YAML;
50-
51-
$this->assertSame(['foo' => [
52-
'bar' => "baz biz\n",
53-
'baz' => "Lorem\nipsum",
54-
'error' => "Une erreur s'est produite.",
55-
'trialMode' => "période d'essai",
56-
'double_line' => "Les utilisateurs sélectionnés n'ont pas d'email.\n",
57-
'a' => "b' c",
58-
'empty' => '',
59-
'foo:bar' => 'foobar',
60-
]], Yaml::parse($yaml));
61-
}
62-
63-
public function testParseWithMultilineQuotesExpectException()
64-
{
65-
$yaml = <<<YAML
66-
foo:
67-
bar: 'baz
68-
69-
'
70-
'
71-
YAML;
72-
73-
$this->expectException(ParseException::class);
74-
$this->expectExceptionMessage('Unable to parse at line 5 (near "\'").');
75-
Yaml::parse($yaml);
76-
}
77-
7827
public function testZeroIndentationThrowsException()
7928
{
8029
$this->expectException(\InvalidArgumentException::class);

0 commit comments

Comments
 (0)