Skip to content

[DI] Fix possible incorrect php-code when dumped strings contains newlines #24532

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

Closed

Conversation

Strate
Copy link
Contributor

@Strate Strate commented Oct 12, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets ?
License MIT
Doc PR no

See discussion #24517

@nicolas-grekas
Copy link
Member

I think you can still create a simple test case that uses a "\n" and ensure the dumped result is OK (without trying to actually fit that with the case where it is required).

@Strate
Copy link
Contributor Author

Strate commented Oct 12, 2017

@nicolas-grekas done

$cleanParts = explode("\n", $value);
$cleanParts = array_map(function ($part) { return var_export($part, true); }, $cleanParts);

return implode(' . "\n" . ', $cleanParts);
Copy link
Member

Choose a reason for hiding this comment

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

spaces around dots should be remove I think, per our CS policy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas sure, already done.

@Strate
Copy link
Contributor Author

Strate commented Oct 12, 2017

Some optimizations could be done, for example now string like "\n\n\n" dumped as ''."\n".''."\n".''."\n".''. Is it reasonable to improve that case?

@nicolas-grekas
Copy link
Member

PHP 7 will concat at compile time, so no need IMHO.

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Oct 12, 2017
@stof
Copy link
Member

stof commented Oct 12, 2017

So var_export does not play well with them ? what about \r then ?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Oct 12, 2017

\r is fine because the real issue is "explode" in "wrapServiceConditionals", which re-indents the code at \n points only.

@nicolas-grekas
Copy link
Member

Thank you @Strate.

nicolas-grekas added a commit that referenced this pull request Oct 12, 2017
…ontains newlines (Strate)

This PR was squashed before being merged into the 2.7 branch (closes #24532).

Discussion
----------

[DI] Fix possible incorrect php-code when dumped strings contains newlines

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | ?
| License       | MIT
| Doc PR        | no

See discussion #24517

<!--
- Bug fixes must be submitted against the lowest branch where they apply
  (lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the 3.4,
  legacy code removals go to the master branch.
- Please fill in this template according to the PR you're about to submit.
- Replace this comment by a description of what your PR is solving.
-->

Commits
-------

345f2fc [DI] Fix possible incorrect php-code when dumped strings contains newlines
This was referenced Nov 10, 2017
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.

6 participants