bug #39168 [Console] Fix console closing tag (jderusse)

This PR was merged into the 4.4 branch.

Discussion
----------

[Console] Fix console closing tag

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

When using SymfonyStyle, in some cases, closing a tag, is called twice.
In the following code `<question>do you want <comment>something</>?</>` the first `</>` close both the `comment` and the `question` tags.

![Screenshot from 2020-11-25 01-21-06](https://user-images.githubusercontent.com/578547/100166475-191d9d80-2ebd-11eb-991a-6541210c479b.png)

The reason is, part of the content is sent in 2 Outputs (see #39160 for another issue), and both outputs share the same `$styleStack`.
This PR updates the `OutputFormatter::__clone` method to prevent sharing the same state.

Commits
-------

2834c279d7 Fix console closing tag
This commit is contained in:
Fabien Potencier 2020-11-25 08:47:56 +01:00
commit 4c378d467e
3 changed files with 22 additions and 0 deletions

View File

@ -25,6 +25,14 @@ class OutputFormatter implements WrappableOutputFormatterInterface
private $styles = [];
private $styleStack;
public function __clone()
{
$this->styleStack = clone $this->styleStack;
foreach ($this->styles as $key => $value) {
$this->styles[$key] = clone $value;
}
}
/**
* Escapes "<" special char in given text.
*

View File

@ -0,0 +1,13 @@
<?php
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
// Ensure that closing tag is applied once
return function (InputInterface $input, OutputInterface $output) {
$output->setDecorated(true);
$output = new SymfonyStyle($input, $output);
$output->write('<question>do you want <comment>something</>');
$output->writeln('?</>');
};

View File

@ -0,0 +1 @@
do you want something?