symfony/symfony — pull request #10193 by robbertkl (2014-02-03 22:28:44+00:00)
Title: [DomCrawler] Fixed incorrect value name conversion in getPhpValues() and getPhpFiles()

| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #6908
| License | MIT
| Doc PR |

Possibly fixes #9009 as well, but not sure how HttpFoundation relates to DomCrawler and how to reproduce there.

The problem is that getPhpValues() and getPhpFiles() depend on parse_str() to do the conversion. While this is a great and reliable way, it has an unwanted side effect: any occurences of a period '.' (as #6908 mentions) or a space ' ' get replaced by an underscore '_'. This results in different values, or even collisions (as 'foo_bar=5&foo.bar=6' would map to foo_bar => 6!). This replacement is specific to PHP and should not happen in DomCrawler\Form, which should support any kind of form.

I ran into this issue while using fabpot/Goutte, which could not post a form field with a name containing '.', while the receiving web server (which isn't running PHP) required this.

PR #9730 tried to fix this in BrowserKit, which doesn't seem to be the correct place, aside from it breaking BC.

This change, however, does not break BC and works by feeding each value through http_build_query() and parse_str() separately, then find the original name and change it back, and finally merging the results with array_replace_recursive().

I've also added 2 simple test cases to FormTest which will ensure this replacement will not sneak back in.