Skip to content
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

Fixed list handing when dealing with object maps #17711

Closed
wants to merge 5 commits into from

Conversation

kleijnweb
Copy link

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #17710, #17709
License MIT
Doc PR N/A

@kleijnweb
Copy link
Author

Build is failing but that has nothing to do with this PR :(

@xabbuh
Copy link
Member

xabbuh commented Feb 7, 2016

Can you give an example of one of the 1% use cases where this would still fail?

@xabbuh xabbuh added the Bug label Feb 7, 2016
@kleijnweb
Copy link
Author

@xabbuh It's probably less than 1%. It's because if you don't make object for object literals at parse time, you can end up with arrays intended as hash maps that are indistinguishable from arrays intended as lists.

    public function testWillParseZeroIndexedNumericMapAsObject()
    {
        $yaml = <<<YAML
map:
  0: one
  1: two
YAML;
        $actual = $this->parser->parse($yaml, true, false, true);
        $this->assertInternalType('object', $actual);
        $this->assertInternalType('object', $actual->map);
    }

The component should definitely be refactored though. Looks pretty daunting, eyeballing it the cyclomatic complexity looks through the roof.

Given the rarity of these cases, I'd say this should not be conditional for this fix though.

@kleijnweb
Copy link
Author

Should anyone else be running into this issue (older versions are affected as well), here's an example that does pretty much the same but on the result (less efficient but does the trick): https://github.com/kleijnweb/swagger-bundle/blob/feature/issue-27/src/Document/YamlParser.php

@xabbuh
Copy link
Member

xabbuh commented Feb 8, 2016

@kleijnweb Can't we simply solve it by checking whether the array was created by parsing a sequence or by parsing a mapping?

@xabbuh xabbuh added Yaml and removed Bug labels Feb 8, 2016
@kleijnweb
Copy link
Author

Sure. But I am not going to touch the parsing logic with a stick. It should be refactored first.

@xabbuh
Copy link
Member

xabbuh commented Feb 8, 2016

Well, I don't see any refactoring being done here soon, but I would like to see this issue solved properly.

@kleijnweb
Copy link
Author

Then I'm afraid we've reached an impasse, because I can't donate that much time right now. So you're left with the following choices:

  1. Wait for someone who doesn't mind hacking into a huge decision tee, in the mean time leave this in the completely broken state that it is
  2. Merge this anyway so that it is fixed for over 99% of use cases. You could leave [YAML] Not handling numeric keys in objects #17709 open, although I would suggest creating a new ticket for hash maps with sequential keys starting at 0.

@xabbuh
Copy link
Member

xabbuh commented Feb 8, 2016

I'll have a look into this later today to check if it turns out to be as easy as I expect it to be. If it proves to be too difficult I agree with you to merge your patch as it already improves the majority of use cases that are affected by this issue.

Anyway, thank you very much for raising the issue and for opening this PR. That's really appreciated!

@javiereguiluz javiereguiluz added this to the 3.1 milestone Feb 8, 2016
@xabbuh
Copy link
Member

xabbuh commented Feb 8, 2016

closing in favour of #17729

@xabbuh xabbuh closed this Feb 8, 2016
@xabbuh
Copy link
Member

xabbuh commented Feb 8, 2016

@kleijnweb Can you please check if #17729 solves all of your issues?

@kleijnweb
Copy link
Author

Tests look good. Nice job :)

fabpot added a commit that referenced this pull request Feb 14, 2016
This PR was merged into the 2.8 branch.

Discussion
----------

[Yaml] properly parse lists in object maps

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17709, #17710, #17711
| License       | MIT
| Doc PR        |
* do not cast parsed sequences to objects
* properly handle numeric mapping keys

Commits
-------

ee9ca93 [Yaml] properly parse lists in object maps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants