Skip to content

[VarDumper] Fix CliDumper coloration on light arrays #36230

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

Merged

Conversation

l-vo
Copy link
Contributor

@l-vo l-vo commented Mar 26, 2020

Q A
Branch? 3.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

When AbstractDumper::DUMP_LIGHT_ARRAY is used with the CliDumper, the first line (opening bracket) is not colored. When an empty array is dumped (with or without AbstractDumper::DUMP_LIGHT_ARRAY) the array is not colored too. This PR aims to fix that.

@@ -268,7 +268,8 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
} elseif (Cursor::HASH_RESOURCE === $type) {
$prefix = $this->style('note', $class.' resource').($hasChild ? ' {' : ' ');
} else {
$prefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? $this->style('note', 'array:'.$class).' [' : '[';
$unstyledPrefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? 'array:'.$class : '';
$prefix = $this->style('note', $unstyledPrefix).($unstyledPrefix ? ' [' : '[');
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I get the logic - why styling the empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because if I don't trigger a coloration (even on an empty string), coloration is not enabled and the open bracket stay uncolored.

Copy link
Member

Choose a reason for hiding this comment

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

the issue in #37674 is precisely complaining about that.

@nicolas-grekas
Copy link
Member

Can you provide a simple script to reproduce the issue? I failed at it.

@l-vo
Copy link
Contributor Author

l-vo commented Jun 14, 2020

Of course 🙂

use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
use Symfony\Component\VarDumper\Dumper\CliDumper;

require __DIR__.'/vendor/autoload.php';

$cliDumper = new CliDumper(null, null, AbstractDumper::DUMP_LIGHT_ARRAY);
$cliDumper->dump((new VarCloner())->cloneVar([]));
$var = ['foo' => 'bar'];
$cliDumper->dump((new VarCloner())->cloneVar(['foo' => 'bar']));

Capture d’écran 2020-06-14 à 15 27 32

[] and first opening bracket of ["foo" => "bar"] aren't colored.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Great thanks.

@nicolas-grekas
Copy link
Member

Can you check the failures on Windows? Maybe you'd like to skip the test case there btw.

@l-vo l-vo force-pushed the fix_clidumper_coloration_light_array branch 14 times, most recently from 4645e0a to 4881712 Compare June 15, 2020 06:40
@l-vo
Copy link
Contributor Author

l-vo commented Jun 15, 2020

I didn't notice that the tests failed on windows; It's fixed, the test is now skipped on this environment.

@l-vo l-vo force-pushed the fix_clidumper_coloration_light_array branch 2 times, most recently from d52165f to 48116af Compare June 15, 2020 07:26
@l-vo l-vo force-pushed the fix_clidumper_coloration_light_array branch from 48116af to 8ad26a8 Compare June 15, 2020 07:27
When using AbstractDumper::DUMP_LIGHT_ARRAY
@l-vo l-vo force-pushed the fix_clidumper_coloration_light_array branch from 8ad26a8 to 7af3469 Compare June 15, 2020 07:49
@nicolas-grekas
Copy link
Member

Thank you @l-vo.

@nicolas-grekas nicolas-grekas merged commit 907ffa0 into symfony:3.4 Jun 18, 2020
fabpot added a commit that referenced this pull request Jul 31, 2020
… (l-vo)

This PR was merged into the 3.4 branch.

Discussion
----------

[VarDumper] Improve previous fix on light array coloration

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37674
| License       | MIT
| Doc PR        |

Improve #36230 to fix #37674 (revert previous fix and use a solution that looks better).

Commits
-------

cef16f5 [VarDumper] Improve previous fix on light array coloration
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.

4 participants