From 075ea6490f7b26831b51839176d6284ea5c839cc Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 Mar 2021 13:24:21 +0100 Subject: [PATCH 1/2] [Console] minor fix --- Helper/QuestionHelper.php | 2 +- Style/SymfonyStyle.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index d211fcfd1..6dde580cf 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -309,7 +309,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu $remainingCharacters = substr($ret, \strlen(trim($this->mostRecentlyEnteredValue($fullChoice)))); $output->write($remainingCharacters); $fullChoice .= $remainingCharacters; - $i = self::strlen($fullChoice); + $i = (false === $encoding = mb_detect_encoding($fullChoice, null, true)) ? \strlen($fullChoice) : mb_strlen($fullChoice, $encoding); $matches = array_filter( $autocomplete($ret), diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index ba89fb422..ecdf9b1a3 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -496,8 +496,6 @@ private function createBlock(iterable $messages, string $type = null, string $st } $line = $prefix.$line; - $decorationLength = Helper::strlen($line) - Helper::strlenWithoutDecoration($this->getFormatter(), $line); - $messageLineLength = min($this->lineLength - $prefixLength - $indentLength + $decorationLength, $this->lineLength); $line .= str_repeat(' ', max($this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $line), 0)); if ($style) { From 1ba4560dbbb9fcf5ae28b61f71f49c678086cf23 Mon Sep 17 00:00:00 2001 From: Roberto Nygaard Date: Thu, 25 Mar 2021 22:22:40 +0000 Subject: [PATCH 2/2] Uses the correct assignment action for console options depending if they are short or long --- Input/ArrayInput.php | 5 +++-- Tests/Input/ArrayInputTest.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Input/ArrayInput.php b/Input/ArrayInput.php index 25d2b750b..bf9a8a455 100644 --- a/Input/ArrayInput.php +++ b/Input/ArrayInput.php @@ -108,12 +108,13 @@ public function __toString() $params = []; foreach ($this->parameters as $param => $val) { if ($param && \is_string($param) && '-' === $param[0]) { + $glue = ('-' === $param[1]) ? '=' : ' '; if (\is_array($val)) { foreach ($val as $v) { - $params[] = $param.('' != $v ? '='.$this->escapeToken($v) : ''); + $params[] = $param.('' != $v ? $glue.$this->escapeToken($v) : ''); } } else { - $params[] = $param.('' != $val ? '='.$this->escapeToken($val) : ''); + $params[] = $param.('' != $val ? $glue.$this->escapeToken($val) : ''); } } else { $params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val); diff --git a/Tests/Input/ArrayInputTest.php b/Tests/Input/ArrayInputTest.php index f3eedb3a2..5777c44b7 100644 --- a/Tests/Input/ArrayInputTest.php +++ b/Tests/Input/ArrayInputTest.php @@ -162,10 +162,10 @@ public function provideInvalidInput() public function testToString() { $input = new ArrayInput(['-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C"]); - $this->assertEquals('-f -b=bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input); + $this->assertEquals('-f -b bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input); $input = new ArrayInput(['-b' => ['bval_1', 'bval_2'], '--f' => ['fval_1', 'fval_2']]); - $this->assertSame('-b=bval_1 -b=bval_2 --f=fval_1 --f=fval_2', (string) $input); + $this->assertSame('-b bval_1 -b bval_2 --f=fval_1 --f=fval_2', (string) $input); $input = new ArrayInput(['array_arg' => ['val_1', 'val_2']]); $this->assertSame('val_1 val_2', (string) $input);