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.17
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.18
Choose a head ref
  • 6 commits
  • 7 files changed
  • 3 contributors

Commits on Nov 30, 2020

  1. Added test for issue 39229

    Nyholm committed Nov 30, 2020
    Copy the full SHA
    8cac71f View commit details
  2. Copy the full SHA
    9919460 View commit details

Commits on Dec 1, 2020

  1. Copy the full SHA
    ae13f07 View commit details
  2. Copy the full SHA
    c4960cd View commit details

Commits on Dec 4, 2020

  1. bug #39267 [Yaml] fix lexing backslashes in single quoted strings (xa…

    …bbuh)
    
    This PR was merged into the 4.4 branch.
    
    Discussion
    ----------
    
    [Yaml] fix lexing backslashes in single quoted strings
    
    | Q             | A
    | ------------- | ---
    | Branch?       | 4.4
    | Bug fix?      | yes
    | New feature?  | no
    | Deprecations? | no
    | Tickets       | Fix #39265
    | License       | MIT
    | Doc PR        |
    
    Commits
    -------
    
    668732305a fix lexing backslashes in single quoted strings
    xabbuh committed Dec 4, 2020
    Copy the full SHA
    8fe9e4e View commit details

Commits on Dec 8, 2020

  1. Apply "visibility_required" CS rule to constants

    php-cs-fixer fix --rules='{"visibility_required": ["property", "method", "const"]}'
    nicolas-grekas committed Dec 8, 2020
    Copy the full SHA
    bbce94f View commit details
Showing with 64 additions and 26 deletions.
  1. +1 −1 Escaper.php
  2. +1 −1 Inline.php
  3. +9 −7 Parser.php
  4. +1 −1 Tests/Command/LintCommandTest.php
  5. +39 −3 Tests/ParserTest.php
  6. +1 −1 Unescaper.php
  7. +12 −12 Yaml.php
2 changes: 1 addition & 1 deletion Escaper.php
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
class Escaper
{
// Characters that would cause a dumped string to require double quoting.
const REGEX_CHARACTER_TO_ESCAPE = "[\\x00-\\x1f]|\x7f|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9";
public const REGEX_CHARACTER_TO_ESCAPE = "[\\x00-\\x1f]|\x7f|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9";

// Mapping arrays for escaping a double quoted string. The backslash is
// first to ensure proper escaping because str_replace operates iteratively
2 changes: 1 addition & 1 deletion Inline.php
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
*/
class Inline
{
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*+(?:\\\\.[^"\\\\]*+)*+)"|\'([^\']*+(?:\'\'[^\']*+)*+)\')';
public const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*+(?:\\\\.[^"\\\\]*+)*+)"|\'([^\']*+(?:\'\'[^\']*+)*+)\')';

public static $parsedLineNumber = -1;
public static $parsedFilename;
16 changes: 9 additions & 7 deletions Parser.php
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@
*/
class Parser
{
const TAG_PATTERN = '(?P<tag>![\w!.\/:-]+)';
const BLOCK_SCALAR_HEADER_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?';
public const TAG_PATTERN = '(?P<tag>![\w!.\/:-]+)';
public const BLOCK_SCALAR_HEADER_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?';

private $filename;
private $offset = 0;
@@ -741,22 +741,22 @@ private function parseValue(string $value, int $flags, string $context)

try {
if ('' !== $value && '{' === $value[0]) {
$cursor = \strlen($this->currentLine) - \strlen($value);
$cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));

return Inline::parse($this->lexInlineMapping($cursor), $flags, $this->refs);
} elseif ('' !== $value && '[' === $value[0]) {
$cursor = \strlen($this->currentLine) - \strlen($value);
$cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));

return Inline::parse($this->lexInlineSequence($cursor), $flags, $this->refs);
}

switch ($value[0] ?? '') {
case '"':
case "'":
$cursor = \strlen($this->currentLine) - \strlen($value);
$cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
$parsedValue = Inline::parse($this->lexInlineQuotedString($cursor), $flags, $this->refs);

if (isset($this->currentLine[$cursor]) && preg_replace('/\s*#.*$/A', '', substr($this->currentLine, $cursor))) {
if (isset($this->currentLine[$cursor]) && preg_replace('/\s*(#.*)?$/A', '', substr($this->currentLine, $cursor))) {
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($this->currentLine, $cursor)));
}

@@ -1170,7 +1170,9 @@ private function lexInlineQuotedString(int &$cursor = 0): string
for (; \strlen($this->currentLine) > $cursor; ++$cursor) {
switch ($this->currentLine[$cursor]) {
case '\\':
if (isset($this->currentLine[++$cursor])) {
if ("'" === $quotation) {
$value .= '\\';
} elseif (isset($this->currentLine[++$cursor])) {
$value .= '\\'.$this->currentLine[$cursor];
}

2 changes: 1 addition & 1 deletion Tests/Command/LintCommandTest.php
Original file line number Diff line number Diff line change
@@ -139,5 +139,5 @@ protected function tearDown(): void

class Foo
{
const TEST = 'foo';
public const TEST = 'foo';
}
42 changes: 39 additions & 3 deletions Tests/ParserTest.php
Original file line number Diff line number Diff line change
@@ -1618,6 +1618,11 @@ public function escapedQuotationCharactersInQuotedStrings()
];
}

public function testBackslashInSingleQuotedString()
{
$this->assertSame(['foo' => 'bar\\'], $this->parser->parse("foo: 'bar\'"));
}

public function testParseMultiLineString()
{
$this->assertEquals("foo bar\nbaz", $this->parser->parse("foo\nbar\n\nbaz"));
@@ -2671,6 +2676,37 @@ public function testParseValueWithNegativeModifiers()
);
}

public function testWhitespaceAtEndOfLine()
{
$yaml = "\nfoo:\n arguments: [ '@bar' ] \n";
$this->assertSame(
[
'foo' => [
'arguments' => ['@bar'],
],
],
$this->parser->parse($yaml)
);

$yaml = "\nfoo:\n bar: {} \n";
$this->assertSame(
[
'foo' => [
'bar' => [],
],
],
$this->parser->parse($yaml)
);

$this->assertSame(
[
'foo' => 'bar',
'foobar' => 'baz',
],
$this->parser->parse("foo: 'bar' \nfoobar: baz")
);
}

/**
* 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.
@@ -2703,7 +2739,7 @@ class B
{
public $b = 'foo';

const FOO = 'foo';
const BAR = 'bar';
const BAZ = 'baz';
public const FOO = 'foo';
public const BAR = 'bar';
public const BAZ = 'baz';
}
2 changes: 1 addition & 1 deletion Unescaper.php
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ class Unescaper
/**
* Regex fragment that matches an escaped character in a double quoted string.
*/
const REGEX_ESCAPED_CHARACTER = '\\\\(x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|.)';
public const REGEX_ESCAPED_CHARACTER = '\\\\(x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|.)';

/**
* Unescapes a single quoted string.
24 changes: 12 additions & 12 deletions Yaml.php
Original file line number Diff line number Diff line change
@@ -22,18 +22,18 @@
*/
class Yaml
{
const DUMP_OBJECT = 1;
const PARSE_EXCEPTION_ON_INVALID_TYPE = 2;
const PARSE_OBJECT = 4;
const PARSE_OBJECT_FOR_MAP = 8;
const DUMP_EXCEPTION_ON_INVALID_TYPE = 16;
const PARSE_DATETIME = 32;
const DUMP_OBJECT_AS_MAP = 64;
const DUMP_MULTI_LINE_LITERAL_BLOCK = 128;
const PARSE_CONSTANT = 256;
const PARSE_CUSTOM_TAGS = 512;
const DUMP_EMPTY_ARRAY_AS_SEQUENCE = 1024;
const DUMP_NULL_AS_TILDE = 2048;
public const DUMP_OBJECT = 1;
public const PARSE_EXCEPTION_ON_INVALID_TYPE = 2;
public const PARSE_OBJECT = 4;
public const PARSE_OBJECT_FOR_MAP = 8;
public const DUMP_EXCEPTION_ON_INVALID_TYPE = 16;
public const PARSE_DATETIME = 32;
public const DUMP_OBJECT_AS_MAP = 64;
public const DUMP_MULTI_LINE_LITERAL_BLOCK = 128;
public const PARSE_CONSTANT = 256;
public const PARSE_CUSTOM_TAGS = 512;
public const DUMP_EMPTY_ARRAY_AS_SEQUENCE = 1024;
public const DUMP_NULL_AS_TILDE = 2048;

/**
* Parses a YAML file into a PHP value.