Skip to content

[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

Merged
merged 1 commit into from
Aug 27, 2014
Merged

Conversation

xabbuh
Copy link
Member

@xabbuh 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
Copy link
Member

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)

@stof
Copy link
Member

stof commented Aug 18, 2014

👍

@stof stof added the Yaml label Aug 18, 2014
@romainneutron
Copy link
Contributor

👍

@fabpot
Copy link
Member

fabpot commented Aug 27, 2014

Thank you @xabbuh.

@fabpot fabpot merged commit 45a5863 into symfony:2.3 Aug 27, 2014
fabpot added a commit that referenced this pull request Aug 27, 2014
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
@xabbuh xabbuh deleted the issue-11665 branch August 27, 2014 12:47
xabbuh added a commit to xabbuh/symfony that referenced this pull request Sep 3, 2014
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: * }").
```
xabbuh added a commit to xabbuh/symfony that referenced this pull request Sep 3, 2014
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: * }").
```
fabpot added a commit that referenced this pull request Sep 4, 2014
…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)) {
Copy link
Contributor

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: [ * ]

Copy link
Member Author

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).

Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tgabi333 Yeah, you're right. The warning has been fixed in #11843. Though a new Symfony version hasn't been released after the change has been merged.

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

Successfully merging this pull request may close these issues.

5 participants