8000 bug #39168 [Console] Fix console closing tag (jderusse) · symfony/symfony@4c378d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c378d4

Browse files
committed
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 ------- 2834c27 Fix console closing tag
2 parents f9d2afb + 2834c27 commit 4c378d4

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/Symfony/Component/Console/Formatter/OutputFormatter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ class OutputFormatter implements WrappableOutputFormatterInterface
2525
private $styles = [];
2626
private $styleStack;
2727

28+
public function __clone()
29+
{
30+
$this->styleStack = clone $this->styleStack;
31+
foreach ($this->styles as $key => $value) {
32+
$this->styles[$key] = clone $value;
33+
}
34+
}
35+
2836
/**
2937
* Escapes "<" special char in given text.
3038
*
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\Style\SymfonyStyle;
6+
7+
// Ensure that closing tag is applied once
8+
return function (InputInterface $input, OutputInterface $output) {
9+
$output->setDecorated(true);
10+
$output = new SymfonyStyle($input, $output);
11+
$output->write('<question>do you want <comment>something</>');
12+
$output->writeln('?</>');
13+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
do you want something?

0 commit comments

Comments
 (0)
0