Skip to content

Two equivalent syntax of yaml-Collections produce different output for the same values #44019

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

Open
gorenstein opened this issue Nov 12, 2021 · 8 comments

Comments

@gorenstein
Copy link

gorenstein commented Nov 12, 2021

Symfony version(s) affected

Tested and reproduced on 4.4 and 5.3

Description

In case the first character of the string is ampersand &, then two equivalent syntax of YAML-Collections produce different output for the same values.

How to reproduce

Add YAML parameters like:

parameters:
    # Correct values in console output  -> ["&string1","&string2","&string3"]
    collection_output_correct:
        - '&string1'
        - "&string2"
        - !!str &string3

    # Wrong values in console output -> ["","","",""]
    collection_output_wrong: ['&string1', "&string2", !!str &string3, &string4 ]

Run bin/console debug:container --parameters and compare output for 'collection_output_correct' and 'collection_output_wrong' parameters.

Possible Solution

No response

Additional Context

No response

@gorenstein gorenstein added the Bug label Nov 12, 2021
@gorenstein gorenstein changed the title Two equivalent syntax of yaml-Collections make different output for the same values Two equivalent syntax of yaml-Collections produce different output for the same values Nov 12, 2021
@xabbuh xabbuh added the Yaml label Nov 12, 2021
@xabbuh
Copy link
Member

xabbuh commented Nov 13, 2021

Can you please try #44034?

fabpot added a commit that referenced this issue Nov 13, 2021
…xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Yaml] don't try to replace references in quoted strings

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #44019
| License       | MIT
| Doc PR        |

Commits
-------

20555ad don't try to replace references in quoted strings
@fabpot fabpot closed this as completed Nov 13, 2021
@gorenstein
Copy link
Author

gorenstein commented Nov 15, 2021

Work fine now for quoted string, but still broken for !!str

parameters:
    # Correct output
    #
    # bin/console debug:container --parameters
    # output -> ["&string"]
    collection_output_correct:
        - !!str &string

    # Wrong output
    #
    # bin/console debug:container --parameters
    # output -> [""]
    collection_output_wrong: [!!str &string]

@xabbuh
Copy link
Member

xabbuh commented Nov 18, 2021

You are right. There was an issue with how we handled quoted scalars tagged with !!str. #44131 will fix that and your YAML should look like this then to work as expected:

parameters:
    # Correct output
    #
    # bin/console debug:container --parameters
    # output -> ["&string"]
    collection_output_correct:
        - !!str '&string'

    # Wrong output
    #
    # bin/console debug:container --parameters
    # output -> [""]
    collection_output_wrong: [!!str '&string']

@gorenstein
Copy link
Author

gorenstein commented Nov 22, 2021

But what about !!str &string - !!str without quoted scalars with the first character &?

Still two equivalent syntax of yaml-Collections produce different output:

parameters:
    collection_1:
        - !!str &string

    collection_2: [!!str &string]
    
    # parser output collection_1: ["&string"]
    # parser output collection_2: [""]

@xabbuh
Copy link
Member

xabbuh commented Nov 22, 2021

You have to quote them. If I do not miss anything, this simply is how it is supposed to be done according to the spec.

@gorenstein
Copy link
Author

I have nothing against this or that specification. I disagree only with the fact that for the same expression, depending on the form of writing the collection (in one line or column), the parser gives different results.
In my opinion, the result should be the same.
No one expects the parser's result to change when you change the collection's spelling from column to line.

@xabbuh
Copy link
Member

xabbuh commented Nov 22, 2021

I was under the expression that the first one would now also end with an empty string. If that’s not the case that should be fixed as well.

@xabbuh xabbuh reopened this Nov 25, 2021
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

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