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

Skip to content

[Yaml] Syntax error not detected in first line of object #33243

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

Closed
SamMousa opened this issue Aug 19, 2019 · 7 comments
Closed

[Yaml] Syntax error not detected in first line of object #33243

SamMousa opened this issue Aug 19, 2019 · 7 comments

Comments

@SamMousa
Copy link

Symfony version(s) affected: v4.3.3

Description
A syntax error is ignored by the parser.

How to reproduce
This code:

paths:
  abc
  abc: def

is successfully parsed but it is not valid YAML.

Additional context
The following online parsers identify the error

I have found several others that also identify the error correctly.

@stof
Copy link
Member

stof commented Aug 19, 2019

what is the result of the parsing ?

@stof stof added the Yaml label Aug 19, 2019
@SamMousa
Copy link
Author

php > var_dump( \Symfony\Component\Yaml\Yaml::parse($config, \Symfony\Component\Yaml\Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE));
array(1) {
  ["paths"]=>
  string(12) "abc abc: def"
}

php > var_dump( \Symfony\Component\Yaml\Yaml::parse($config));
array(1) {
  ["paths"]=>
  string(12) "abc abc: def"
}

Hmm, when reporting a parser bug it obviously makes sense to put in the parse result.. ^^

@SamMousa
Copy link
Author

For completeness' sake:

php > echo strtr($config, ["\r" => '#13', "\n" => '#10']);
paths:#10  abc#10  abc: def#10

@xabbuh
Copy link
Member

xabbuh commented Aug 23, 2019

Since #27898 which is part of Symfony 4.3 the given example should trigger a deprecation warning ("Support for mapping keys in multi-line blocks is deprecated") and will fail with a ParseException in Symfony 5.

@SamMousa Can you confirm that's the case or create a small reproducible example application otherwise?

@SamMousa
Copy link
Author

Added to my todo.!

@xabbuh
Copy link
Member

xabbuh commented Aug 29, 2019

@SamMousa Did you manage to check for the deprecation?

@SamMousa
Copy link
Author

SamMousa commented Aug 29, 2019

Yes, just confirmed it.

require 'vendor/autoload.php';

use Symfony\Component\Yaml\Yaml;
$yaml = <<<YAML
paths:
  abc
  abc: def
YAML;
set_error_handler(function($code, $message, $file, $line, $context) {
    throw new \Exception($message);
});
Yaml::parse($yaml);

Result:

PHP Fatal error:  Uncaught Exception: Support for mapping keys in multi-line blocks is deprecated since Symfony 4.3 and will throw a ParseException in 5.0. in /tmp/yaml/test.php:12
Stack trace:
#0 [internal function]: {closure}(16384, 'Support for map...', '/tmp/yaml/vendo...', 396, Array)
#1 /tmp/yaml/vendor/symfony/yaml/Parser.php(396): trigger_error('Support for map...', 16384)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants