-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[YAML] resolve variables in inlined YAML #11677
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
Conversation
xabbuh
commented
Aug 15, 2014
Q | A |
---|---|
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #11665 |
License | MIT |
Doc PR | |
#11569 does not resolve variables in inline YAML. |
array('[ key: *var ]', array(array('key' => 'var-value'))), // embedded mapping | ||
array('{ key: *var }', array('key' => 'var-value')), | ||
array('{ key: [*var] }', array('key' => array('var-value'))), // list in map | ||
array('{ foo: { bar: *var } }', array('foo' => array('bar' => 'var-value'))), // map in map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of putting comments to describe the dataset, you should use the keys in the main array to name your datasets (this way, it also appears in failure messages rather than getting a numeric index)
👍 |
👍 |
Thank you @xabbuh. |
This PR was merged into the 2.3 branch. Discussion ---------- [YAML] resolve variables in inlined YAML | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11665 | License | MIT | Doc PR | #11569 does not resolve variables in inline YAML. Commits ------- 45a5863 [YAML] resolve variables in inlined YAML
Asterisks in unquoted strings are used in YAML to reference variables. Before Symfony 2.3.19, Symfony 2.4.9 and Symfony 2.5.4, unquoted asterisks in inlined YAML code were treated as regular strings. This was fixed for the inline parser in symfony#11677. However, an unquoted * character now led to an error message like this: ``` PHP Warning: array_key_exists(): The first argument should be either a string or an integer in vendor/symfony/symfony/src/Symfony/Component/Yaml/Inline.php on line 409 [Symfony\Component\Yaml\Exception\ParseException] Reference "" does not exist at line 171 (near "- { foo: * }"). ```
Asterisks in unquoted strings are used in YAML to reference variables. Before Symfony 2.3.19, Symfony 2.4.9 and Symfony 2.5.4, unquoted asterisks in inlined YAML code were treated as regular strings. This was fixed for the inline parser in symfony#11677. However, an unquoted * character now led to an error message like this: ``` PHP Warning: array_key_exists(): The first argument should be either a string or an integer in vendor/symfony/symfony/src/Symfony/Component/Yaml/Inline.php on line 409 [Symfony\Component\Yaml\Exception\ParseException] Reference "" does not exist at line 171 (near "- { foo: * }"). ```
…isks (xabbuh) This PR was merged into the 2.3 branch. Discussion ---------- [Yaml] improve error message when detecting unquoted asterisks | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11835 | License | MIT | Doc PR | Asterisks in unquoted strings are used in YAML to reference variables. Before Symfony 2.3.19, Symfony 2.4.9 and Symfony 2.5.4, unquoted asterisks in inlined YAML code were treated as regular strings. This was fixed for the inline parser in #11677. However, an unquoted * character now led to an error message like this: ``` PHP Warning: array_key_exists(): The first argument should be either a string or an integer in vendor/symfony/symfony/src/Symfony/Component/Yaml/Inline.php on line 409 [Symfony\Component\Yaml\Exception\ParseException] Reference "" does not exist at line 171 (near "- { foo: * }"). ``` Commits ------- 854e07b improve error when detecting unquoted asterisks
$value = substr($scalar, 1); | ||
} | ||
|
||
if (!array_key_exists($value, $references)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We run into a problem upgrading to 2.5.4 which contains this PR. Our - previously invalid - YAML contained unescaped asterix character both as a key and value in several places. After upgrading, this call raised php warnings about the first parameter.
eg: arguments: [ * ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's because the asterisk has a special meaning in YAML. This wasn't handled properly before. You have to enclose it in quotes to tell the parser that it is just a main character but no reference (see also #11835 and symfony/symfony-docs#4197).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but what i found here is a coding problem, this code should not call array_key_exists with wrong parameters generating a php warning, instead, it should throw a ParseException.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.