Skip to content

New DUMP_MULTI_LINE_LITERAL_BLOCK doesn't indent at all #17977

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
schorsch3000 opened this issue Mar 1, 2016 · 4 comments
Closed

New DUMP_MULTI_LINE_LITERAL_BLOCK doesn't indent at all #17977

schorsch3000 opened this issue Mar 1, 2016 · 4 comments
Labels

Comments

@schorsch3000
Copy link

Hi,
i've tested the new DUMP_MULTI_LINE_LITERAL_BLOCK which got into master a few days ago with eff6902. It seems it doesn't indent the literal block at all as it should.

i've used 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);

while requiring "symfony/yaml": "dev-master"

the string in $yaml is:

foo: bar
error: |
foo
bar

it should be:

foo: bar
error: |
    foo
    bar

that's because the parser 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

I don't think that it matters, but since the bug report guidelines talk about this stuff, here are some of my details:

$ cat /etc/debian_version 
8.3
$ uname -a
Linux localhost 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64 GNU/Linux
$ php -v
PHP 5.6.17-0+deb8u1 (cli) (built: Jan 13 2016 09:10:12) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with XCache v3.2.0, Copyright (c) 2005-2014, by mOo
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
    with XCache Optimizer v3.2.0, Copyright (c) 2005-2014, by mOo
    with XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo
    with XCache Coverager v3.2.0, Copyright (c) 2005-2014, by mOo
$ grep -A 12 '"name": "symfony/yaml"'  composer.lock 
            "name": "symfony/yaml",
            "version": "dev-master",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/yaml.git",
                "reference": "c9821ffc2965d57b0404e40ef08dc8da642238f2"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/yaml/zipball/c9821ffc2965d57b0404e40ef08dc8da642238f2",
                "reference": "c9821ffc2965d57b0404e40ef08dc8da642238f2",
                "shasum": ""
            },



@schorsch3000
Copy link
Author

Sorry, seems like i've set indentation to 0 which clearly leads to no indentation at all.
i've got that idea from the testcase:

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

which i've copied straight away without thinking about what i do.

So, that test-case seems odd to me.
Also, it it okay that i can choose to not indent at all which will break the syntax?

@xabbuh
Copy link
Member

xabbuh commented Mar 1, 2016

@schorsch3000 Well, when using the Dumper class you would pass the indentation to the constructor. The $indent argument of the Dumper::dump() method is only used internally. However, I agree with you that we should prevent users from being able to do that at all. So I opened #17978 and #17979 to throw exceptions then.

@schorsch3000
Copy link
Author

@xabbuh Everything seems fine now that i handle the dumper right, Thanks for working on that, and thanks for that fast support that late!

@xabbuh
Copy link
Member

xabbuh commented Mar 1, 2016

@schorsch3000 You're welcome. And thanks once again for testing. :)

fabpot added a commit that referenced this issue 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants