Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41a450b

Browse files
minor #33523 Fix lint commands frozen on empty stdin (chalasr)
This PR was merged into the 4.4 branch. Discussion ---------- Fix lint commands frozen on empty stdin | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Running e.g. `lint:yaml -` with no piped content makes the command hangs currently, this makes it fail instead. Also fixes the command help which we forgot to update Commits ------- b60e0c1 Fix lint commands frozen on empty stdin
2 parents 92ef476 + b60e0c1 commit 41a450b

File tree

6 files changed

+33
-61
lines changed

6 files changed

+33
-61
lines changed

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function configure()
5757
5858
You can validate the syntax of contents passed from STDIN:
5959
60-
<info>cat filename | php %command.full_name%</info>
60+
<info>cat filename | php %command.full_name% -</info>
6161
6262
Or the syntax of a file:
6363
@@ -77,13 +77,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
7777
{
7878
$io = new SymfonyStyle($input, $output);
7979
$filenames = $input->getArgument('filename');
80-
$hasStdin = ['-'] === $filenames;
8180

82-
if ($hasStdin || !$filenames) {
83-
if ($hasStdin || 0 === ftell(STDIN)) { // remove 0 === ftell(STDIN) check in 5.0
84-
if (!$hasStdin) {
85-
@trigger_error('Calling to the "lint:twig" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
86-
}
81+
if (['-'] === $filenames) {
82+
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
83+
}
84+
85+
if (!$filenames) {
86+
// @deprecated to be removed in 5.0
87+
if (0 === ftell(STDIN)) {
88+
@trigger_error('Piping content from STDIN to the "lint:twig" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
8789

8890
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
8991
}
@@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9799
$filenames = array_merge(...$paths);
98100
}
99101

100-
if (0 === \count($filenames)) {
102+
if (!$filenames) {
101103
throw new RuntimeException('Please provide a filename or pipe template content to STDIN.');
102104
}
103105
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/XliffLintCommandTest.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,12 @@ public function testGetHelp()
3535
{
3636
$command = new XliffLintCommand();
3737
$expected = <<<EOF
38-
The <info>%command.name%</info> command lints a XLIFF file and outputs to STDOUT
39-
the first encountered syntax error.
40-
41-
You can validates XLIFF contents passed from STDIN:
42-
43-
<info>cat filename | php %command.full_name%</info>
44-
45-
You can also validate the syntax of a file:
46-
47-
<info>php %command.full_name% filename</info>
48-
49-
Or of a whole directory:
50-
51-
<info>php %command.full_name% dirname</info>
52-
<info>php %command.full_name% dirname --format=json</info>
53-
5438
Or find all files in a bundle:
5539
5640
<info>php %command.full_name% @AcmeDemoBundle</info>
57-
5841
EOF;
5942

60-
$this->assertEquals($expected, $command->getHelp());
43+
$this->assertStringContainsString($expected, $command->getHelp());
6144
}
6245

6346
public function testLintFilesFromBundleDirectory()

src/Symfony/Bundle/FrameworkBundle/Tests/Command/YamlLintCommandTest.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,12 @@ public function testGetHelp()
7272
{
7373
$command = new YamlLintCommand();
7474
$expected = <<<EOF
75-
The <info>%command.name%</info> command lints a YAML file and outputs to STDOUT
76-
the first encountered syntax error.
77-
78-
You can validates YAML contents passed from STDIN:
79-
80-
<info>cat filename | php %command.full_name%</info>
81-
82-
You can also validate the syntax of a file:
83-
84-
<info>php %command.full_name% filename</info>
85-
86-
Or of a whole directory:
87-
88-
<info>php %command.full_name% dirname</info>
89-
<info>php %command.full_name% dirname --format=json</info>
90-
9175
Or find all files in a bundle:
9276
9377
<info>php %command.full_name% @AcmeDemoBundle</info>
94-
9578
EOF;
9679

97-
$this->assertEquals($expected, $command->getHelp());
80+
$this->assertStringContainsString($expected, $command->getHelp());
9881
}
9982

10083
public function testLintFilesFromBundleDirectory()

src/Symfony/Component/Translation/Command/XliffLintCommand.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function configure()
6161
6262
You can validates XLIFF contents passed from STDIN:
6363
64-
<info>cat filename | php %command.full_name%</info>
64+
<info>cat filename | php %command.full_name% -</info>
6565
6666
You can also validate the syntax of a file:
6767
@@ -83,16 +83,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
8383
$filenames = (array) $input->getArgument('filename');
8484
$this->format = $input->getOption('format');
8585
$this->displayCorrectFiles = $output->isVerbose();
86-
$hasStdin = ['-'] === $filenames;
8786

88-
if ($hasStdin || !$filenames) {
89-
if (!$hasStdin && 0 !== ftell(STDIN)) { // remove 0 !== ftell(STDIN) check in 5.0
87+
if (['-'] === $filenames) {
88+
return $this->display($io, [$this->validate($this->getStdin())]);
89+
}
90+
91+
// @deprecated to be removed in 5.0
92+
if (!$filenames) {
93+
if (0 !== ftell(STDIN)) {
9094
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
9195
}
9296

93-
if (!$hasStdin) {
94-
@trigger_error('Calling to the "lint:xliff" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
95-
}
97+
@trigger_error('Piping content from STDIN to the "lint:xliff" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
9698

9799
return $this->display($io, [$this->validate($this->getStdin())]);
98100
}

src/Symfony/Component/Translation/Tests/Command/XliffLintCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function testGetHelp()
124124
125125
You can validates XLIFF contents passed from STDIN:
126126
127-
<info>cat filename | php %command.full_name%</info>
127+
<info>cat filename | php %command.full_name% -</info>
128128
129129
You can also validate the syntax of a file:
130130

src/Symfony/Component/Yaml/Command/LintCommand.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function configure()
6363
6464
You can validates YAML contents passed from STDIN:
6565
66-
<info>cat filename | php %command.full_name%</info>
66+
<info>cat filename | php %command.full_name% -</info>
6767
6868
You can also validate the syntax of a file:
6969
@@ -86,18 +86,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
8686
$this->format = $input->getOption('format');
8787
$this->displayCorrectFiles = $output->isVerbose();
8888
$flags = $input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS : 0;
89-
$hasStdin = ['-'] === $filenames;
9089

91-
if ($hasStdin || !$filenames) {
92-
if (!$hasStdin && 0 !== ftell(STDIN)) { // remove 0 !== ftell(STDIN) check in 5.0
93-
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
94-
}
90+
if (['-'] === $filenames) {
91+
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
92+
}
9593

96-
if (!$hasStdin) {
97-
@trigger_error('Calling to the "lint:yaml" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
94+
// @deprecated to be removed in 5.0
95+
if (!$filenames) {
96+
if (0 === ftell(STDIN)) {
97+
@trigger_error('Piping content from STDIN to the "lint:yaml" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
98+
99+
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
98100
}
99101

100-
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
102+
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
101103
}
102104

103105
$filesInfo = [];

0 commit comments

Comments
 (0)