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

[Yaml] option to dump multi line strings as scalar blocks #17943

Merged
merged 1 commit into from Mar 1, 2016

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Feb 27, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16236, #16604, #17912, #17391
License MIT
Doc PR symfony/symfony-docs#6226

$prefix,
str_repeat(' ', $this->indentation),
$dumpedRow
);
Copy link
Member

Choose a reason for hiding this comment

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

This should probably on one line.

@fabpot
Copy link
Member

fabpot commented Feb 29, 2016

👍

@@ -84,6 +84,30 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0)
$isAHash = array_keys($input) !== range(0, count($input) - 1);

foreach ($input as $key => $value) {
if ($inline - 1 > 0 && Yaml::DUMP_MULTI_LINE_AS_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n")) {
Copy link
Member

Choose a reason for hiding this comment

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

I would say $inline > 1, to avoid an operation (even though OPCache might be able to detect this optimization)

@xabbuh xabbuh force-pushed the issue-16236 branch 4 times, most recently from 7175f64 to b438a68 Compare March 1, 2016 15:32
@xabbuh
Copy link
Member Author

xabbuh commented Mar 1, 2016

I would like to rename the DUMP_MULTI_LINE_AS_BLOCK constant to DUMP_MULTI_LINE_LITERAL_BLOCK. What do you think?

@fabpot
Copy link
Member

fabpot commented Mar 1, 2016

The rename sounds like a good idea to me.

@xabbuh
Copy link
Member Author

xabbuh commented Mar 1, 2016

I renamed the constant and added a changelog entry. This is ready for the final review.

@stof
Copy link
Member

stof commented Mar 1, 2016

👍

We will need a doc PR for that though

@fabpot
Copy link
Member

fabpot commented Mar 1, 2016

Thank you @xabbuh.

@fabpot fabpot merged commit eff6902 into symfony:master Mar 1, 2016
fabpot added a commit that referenced this pull request Mar 1, 2016
…cks (xabbuh)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Yaml] option to dump multi line strings as scalar blocks

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16236, #16604, #17912, #17391
| License       | MIT
| Doc PR        | TODO

Commits
-------

eff6902 option to dump multi line strings as scalar blocks
@xabbuh xabbuh deleted the issue-16236 branch March 1, 2016 17:34
@schorsch3000
Copy link

Hi,
nice to see someone worked on that, thanks :)

i'm not sure if i'm doing something horrible wrong of if there is something buggy.
i'm requiring "symfony/yaml": "dev-master" with composer.

Running this simple example

<?php
include 'vendor/autoload.php';
use Symfony\Component\Yaml\Yaml;
$data = ['foo' => 'bar', 'error' => "foo\nbar"];
$yaml = Yaml::dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
Yaml::parse($yaml);;

throws

Fatal error: Uncaught exception 'Symfony\Component\Yaml\Exception\ParseException' with message 'Unable to parse at line 3 (near "foo").' in vendor/symfony/yaml/Parser.php on line 321

the resulting string in $yaml is:

foo: bar
error: |
foo
bar

foo and bar is not indented, why is that?

Thanks, Dirk

@xabbuh
Copy link
Member Author

xabbuh commented Mar 1, 2016

@schorsch3000 Sorry for that and thank you for testing the new feature. :) Would you mind opening an issue for this? It looks indeed like a bug to me.

@schorsch3000
Copy link

No problem, if my wishes get fullfilled im fine doing beta-testing :)
Sure, i'll report a bug, i just wanted to know id i did something wrong :)

@xabbuh
Copy link
Member Author

xabbuh commented Mar 1, 2016

@schorsch3000 Oh wait, I just noticed that you passed 0 as the number of spaces to indent. This number must in fact be greater than zero.

@schorsch3000
Copy link

Damn, i've just reported that bug.
yes, with a sane number there everything is fine.
i've copied the call from the test-case:

$this->dumper->dump($data, 3, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));

without thinking about it.
seems this test-case is odd?

@xabbuh
Copy link
Member Author

xabbuh commented Mar 1, 2016

@schorsch3000 I put some explanation in #17977 (comment).

@xabbuh xabbuh mentioned this pull request Mar 1, 2016
7 tasks
@xabbuh
Copy link
Member Author

xabbuh commented Mar 1, 2016

@stof I have now added all new YAML features to the list in symfony/symfony-docs#6226.

fabpot added a commit that referenced this pull request Mar 2, 2016
…abbuh)

This PR was merged into the 2.3 branch.

Discussion
----------

[Yaml] ensure dump indentation to be greather than zero

| Q             | A
| ------------- | ---
| Branch        | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17943 (comment), #17977
| License       | MIT
| Doc PR        |

Commits
-------

3464282 ensure dump indentation to be greather than zero
@fabpot fabpot mentioned this pull request May 13, 2016
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

5 participants