Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  fix merge
  drop logger mock in favor of using the BufferingLogger
  catch ValueError thrown on PHP 8
  [Yaml Parser] Fix edge cases when parsing multiple documents
  fix parsing comments not prefixed by a space
  [Translator] Make sure a null locale is handled properly
  deal with errors being thrown on PHP 8
  [Cache] Allow cache tags to be objects implementing __toString()
  [HttpKernel] Do not override max_redirects option in HttpClientKernel
  remove superfluous cast
  [HttpClient] Support for CURLOPT_LOCALPORT.
  Upgrade PHPUnit to 8.5 (php 7.2) and 9.3 (php >= 7.3).
  Fixed exception message formatting
  [FrameworkBundle] Fix error in xsd which prevent to register more than one metadata
  [Console] work around disabled putenv()
  [PhpUnitBridge] Fix error with ReflectionClass
  [HttpClient][HttpClientTrait] don't calculate alternatives if option is auth_ntlm
  Change 'cache_key' to AbstractRendererEngine::CACHE_KEY_VAR
  Upgrade PHPUnit to 8.5 (php 7.2) and 9.3 (php >= 7.3).
  • Loading branch information
xabbuh committed Sep 18, 2020
2 parents 700095b + 55f2c00 commit ab2d6c0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function parse(string $value = null, int $flags = 0, array $refere
}

// some comments are allowed at the end
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
if (preg_replace('/\s*#.*$/A', '', substr($value, $i))) {
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
}

Expand Down
3 changes: 2 additions & 1 deletion Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function parse(string $value, int $flags = 0)
$this->refs = [];
$this->skippedLineNumbers = [];
$this->locallySkippedLineNumbers = [];
$this->totalNumberOfLines = null;
}

return $data;
Expand Down Expand Up @@ -728,7 +729,7 @@ private function parseValue(string $value, int $flags, string $context)
if (\in_array($value[0], ['!', '|', '>'], true) && self::preg_match('/^(?:'.self::TAG_PATTERN.' +)?'.self::BLOCK_SCALAR_HEADER_PATTERN.'$/', $value, $matches)) {
$modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';

$data = $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs((int) $modifiers));
$data = $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), abs((int) $modifiers));

if ('' !== $matches['tag'] && '!' !== $matches['tag']) {
if ('!!binary' === $matches['tag']) {
Expand Down
10 changes: 10 additions & 0 deletions Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,16 @@ public function testParseNegativeOctalNumberContainingInvalidDigits()
self::assertSame('-0123456789', Inline::parse('-0123456789'));
}

public function testParseCommentNotPrefixedBySpaces()
{
self::assertSame('foo', Inline::parse('"foo"#comment'));
}

public function testParseUnquotedStringContainingHashTagNotPrefixedBySpace()
{
self::assertSame('foo#nocomment', Inline::parse('foo#nocomment'));
}

/**
* @dataProvider unquotedExclamationMarkThrowsProvider
*/
Expand Down
33 changes: 33 additions & 0 deletions Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,39 @@ public function testParseValueWithNegativeModifiers()
$this->parser->parse($yaml)
);
}

/**
* This is a regression test for a bug where a YAML block with a nested multiline string using | was parsed without
* a trailing \n when a shorter YAML document was parsed before.
*
* When a shorter document was parsed before, the nested string did not have a \n at the end of the string, because
* the Parser thought it was the end of the file, even though it is not.
*/
public function testParsingMultipleDocuments()
{
$shortDocument = 'foo: bar';
$longDocument = <<<YAML
a:
b: |
row
row2
c: d
YAML;

$expected = ['a' => ['b' => "row\nrow2\n"], 'c' => 'd'];

// The parser was not used before, so there is a new line after row2
$this->assertSame($expected, $this->parser->parse($longDocument));

$parser = new Parser();
// The first parsing set and fixed the totalNumberOfLines in the Parser before, so parsing the short document here
// to reproduce the issue. If the issue would not have been fixed, the next assertion will fail
$parser->parse($shortDocument);

// After the total number of lines has been rset the result will be the same as if a new parser was used
// (before, there was no \n after row2)
$this->assertSame($expected, $parser->parse($longDocument));
}
}

class B
Expand Down

0 comments on commit ab2d6c0

Please sign in to comment.