Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Yaml] Fix String offset cast error in Inline parser #20335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,10 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar

// key
$key = self::parseScalar($mapping, $flags, array(':', ' '), array('"', "'"), $i, false);
$i = strpos($mapping, ':', $i);

if (false === $i = strpos($mapping, ':', $i)) {
break;
}

if (!isset($mapping[$i + 1]) || ' ' !== $mapping[$i + 1]) {
@trigger_error('Omitting the space after the colon that follows a mapping key definition is deprecated since version 3.2 and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,13 @@ public function getInvalidBinaryData()
'misplaced equals character' => array('!!binary "SGVsbG8gd29ybG=Q"', '/The base64 encoded data \(.*\) contains invalid characters/'),
);
}

/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Malformed inline YAML string {this, is not, yaml}
*/
public function testStringOffsetCastError()
{
Inline::parse('{this, is not, yaml}');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is valid and should be equivalent to { this: ~, is not: ~, yaml: ~ }.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. But this string wasn't even parsed before, was it? But we should nonetheless choose a better failing test case here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly i have no idea if it worked, this part of the code is really hard to understand and i'm certain it leads to unexpected behaviors (by reading it, i think { foo bar } results to { foo: bar }).
I don't think this is the right fix even if it would prevent some unexpected behaviors, this part of the code has to be rewritten to be clearer and more testable.

}
}