Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/yaml
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.4.5
Choose a base ref
...
head repository: symfony/yaml
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.4.6
Choose a head ref
  • 7 commits
  • 5 files changed
  • 3 contributors

Commits on Mar 9, 2020

  1. Copy the full SHA
    8874912 View commit details
  2. bug #36004 [Yaml] fix dumping strings containing CRs (xabbuh)

    This PR was merged into the 3.4 branch.
    
    Discussion
    ----------
    
    [Yaml] fix dumping strings containing CRs
    
    | Q             | A
    | ------------- | ---
    | Branch?       | 3.4
    | Bug fix?      | yes
    | New feature?  | no
    | Deprecations? | no
    | Tickets       |
    | License       | MIT
    | Doc PR        |
    
    Commits
    -------
    
    da7870433f [Yaml] fix dumping strings containing CRs
    fabpot committed Mar 9, 2020
    Copy the full SHA
    37d6a73 View commit details

Commits on Mar 11, 2020

  1. Merge branch '3.4' into 4.4

    * 3.4:
      [Yaml] fix dumping strings containing CRs
      [DI] Fix XmlFileLoader bad error message
      Tweak message
      improve PlaintextPasswordEncoder docBlock summary
      [Validator] Add two missing translations for the Arabic (ar) locale
      Use some PHP 5.4 constants unconditionally
      Revert "bug symfony#28179 [DomCrawler] Skip disabled fields processing in Form"
      Add Spanish translation
      Fix typo
      [Validator] add Japanese translation
      Fix typo
      Add Polish translation
      [SecurityBundle] Minor fixes in configuration tree builder
      bumped Symfony version to 3.4.39
      updated VERSION for 3.4.38
      update CONTRIBUTORS for 3.4.38
      updated CHANGELOG for 3.4.38
    nicolas-grekas committed Mar 11, 2020
    Copy the full SHA
    28f08c4 View commit details

Commits on Mar 15, 2020

  1. Copy the full SHA
    d54c2a8 View commit details
  2. Merge branch '3.4' into 4.4

    * 3.4:
      Add missing dots at the end of exception messages
    fabpot committed Mar 15, 2020
    Copy the full SHA
    5342b6f View commit details

Commits on Mar 16, 2020

  1. Copy the full SHA
    688cfb1 View commit details
  2. Merge branch '3.4' into 4.4

    * 3.4:
      Fix quotes in exception messages
    fabpot committed Mar 16, 2020
    Copy the full SHA
    43d7a46 View commit details
Showing with 24 additions and 9 deletions.
  1. +1 −1 Dumper.php
  2. +4 −4 Inline.php
  3. +2 −2 Parser.php
  4. +16 −1 Tests/DumperTest.php
  5. +1 −1 Tests/InlineTest.php
2 changes: 1 addition & 1 deletion Dumper.php
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
$dumpAsMap = Inline::isHash($input);

foreach ($input as $key => $value) {
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r\n")) {
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r")) {
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
// http://www.yaml.org/spec/1.2/spec.html#id2793979
$blockIndentationIndicator = (' ' === substr($value, 0, 1)) ? (string) $this->indentation : '';
8 changes: 4 additions & 4 deletions Inline.php
Original file line number Diff line number Diff line change
@@ -297,7 +297,7 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
$i += \strlen($output);
$output = trim($output);
} else {
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar), self::$parsedLineNumber + 1, null, self::$parsedFilename);
throw new ParseException(sprintf('Malformed inline YAML string: "%s".', $scalar), self::$parsedLineNumber + 1, null, self::$parsedFilename);
}

// a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >)
@@ -321,7 +321,7 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
private static function parseQuotedScalar(string $scalar, int &$i): string
{
if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
throw new ParseException(sprintf('Malformed inline YAML string: "%s".', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
}

$output = substr($match[0], 1, \strlen($match[0]) - 2);
@@ -397,7 +397,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
++$i;
}

throw new ParseException(sprintf('Malformed inline YAML string: %s.', $sequence), self::$parsedLineNumber + 1, null, self::$parsedFilename);
throw new ParseException(sprintf('Malformed inline YAML string: "%s".', $sequence), self::$parsedLineNumber + 1, null, self::$parsedFilename);
}

/**
@@ -538,7 +538,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
}
}

throw new ParseException(sprintf('Malformed inline YAML string: %s.', $mapping), self::$parsedLineNumber + 1, null, self::$parsedFilename);
throw new ParseException(sprintf('Malformed inline YAML string: "%s".', $mapping), self::$parsedLineNumber + 1, null, self::$parsedFilename);
}

/**
4 changes: 2 additions & 2 deletions Parser.php
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ private function doParse(string $value, int $flags)
$isRef = $mergeNode = false;
if ('-' === $this->currentLine[0] && self::preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+))?$#u', rtrim($this->currentLine), $values)) {
if ($context && 'mapping' == $context) {
throw new ParseException('You cannot define a sequence item when in a mapping', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
throw new ParseException('You cannot define a sequence item when in a mapping.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
}
$context = 'sequence';

@@ -199,7 +199,7 @@ private function doParse(string $value, int $flags)
&& (false === strpos($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
) {
if ($context && 'sequence' == $context) {
throw new ParseException('You cannot define a mapping item when in a sequence', $this->currentLineNb + 1, $this->currentLine, $this->filename);
throw new ParseException('You cannot define a mapping item when in a sequence.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
}
$context = 'mapping';

17 changes: 16 additions & 1 deletion Tests/DumperTest.php
Original file line number Diff line number Diff line change
@@ -547,11 +547,26 @@ public function testDumpMultiLineStringAsScalarBlockWhenFirstLineHasLeadingSpace
$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block_leading_space_in_first_line.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
}

public function testCarriageReturnIsMaintainedWhenDumpingAsMultiLineLiteralBlock()
public function testCarriageReturnFollowedByNewlineIsMaintainedWhenDumpingAsMultiLineLiteralBlock()
{
$this->assertSame("- \"a\\r\\nb\\nc\"\n", $this->dumper->dump(["a\r\nb\nc"], 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
}

public function testCarriageReturnNotFollowedByNewlineIsPreservedWhenDumpingAsMultiLineLiteralBlock()
{
$expected = <<<'YAML'
parent:
foo: "bar\n\rbaz: qux"

YAML;

$this->assertSame($expected, $this->dumper->dump([
'parent' => [
'foo' => "bar\n\rbaz: qux",
],
], 4, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
}

public function testZeroIndentationThrowsException()
{
$this->expectException('InvalidArgumentException');
2 changes: 1 addition & 1 deletion Tests/InlineTest.php
Original file line number Diff line number Diff line change
@@ -617,7 +617,7 @@ public function getInvalidBinaryData()
public function testNotSupportedMissingValue()
{
$this->expectException('Symfony\Component\Yaml\Exception\ParseException');
$this->expectExceptionMessage('Malformed inline YAML string: {this, is not, supported} at line 1.');
$this->expectExceptionMessage('Malformed inline YAML string: "{this, is not, supported}" at line 1.');
Inline::parse('{this, is not, supported}');
}