Skip to content

Commit 8121de6

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Console] Fix `Helper::removeDecoration` hyperlink bug Guard scripts from being run in non-CLI contexts Guard scripts from being run in non-CLI contexts a readonly property must not be reported as being writable
2 parents e3d8890 + e9607d0 commit 8121de6

File tree

18 files changed

+115
-2
lines changed

18 files changed

+115
-2
lines changed

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
// Please update when phpunit needs to be reinstalled with fresh deps:
1313
// Cache-Id: 2021-02-04 11:00 UTC
1414

15+
if ('cli' !== \PHP_SAPI && 'phpdbg' !== \PHP_SAPI) {
16+
throw new Exception('This script must be run from the command line.');
17+
}
18+
1519
error_reporting(-1);
1620

1721
global $argv, $argc;

src/Symfony/Bundle/FrameworkBundle/Resources/bin/check-unused-known-tags.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
* file that was distributed with this source code.
1010
*/
1111

12+
if ('cli' !== \PHP_SAPI) {
13+
throw new Exception('This script must be run from the command line.');
14+
}
15+
1216
require dirname(__DIR__, 6).'/vendor/autoload.php';
1317

1418
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\UnusedTagsPassUtils;

src/Symfony/Component/Console/Helper/Helper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public static function removeDecoration(OutputFormatterInterface $formatter, ?st
145145
$string = $formatter->format($string ?? '');
146146
// remove already formatted characters
147147
$string = preg_replace("/\033\[[^m]*m/", '', $string ?? '');
148+
// remove terminal hyperlinks
149+
$string = preg_replace('/\\033]8;[^;]*;[^\\033]*\\033\\\\/', '', $string ?? '');
148150
$formatter->setDecorated($isDecorated);
149151

150152
return $string;

src/Symfony/Component/Console/Tests/Helper/HelperTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Console\Tests\Helper;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Formatter\OutputFormatter;
1516
use Symfony\Component\Console\Helper\Helper;
1617

1718
class HelperTest extends TestCase
@@ -42,6 +43,16 @@ public function formatTimeProvider()
4243
];
4344
}
4445

46+
public function decoratedTextProvider()
47+
{
48+
return [
49+
['abc', 'abc'],
50+
['abc<fg=default;bg=default>', 'abc'],
51+
["a\033[1;36mbc", 'abc'],
52+
["a\033]8;;http://url\033\\b\033]8;;\033\\c", 'abc'],
53+
];
54+
}
55+
4556
/**
4657
* @dataProvider formatTimeProvider
4758
*
@@ -52,4 +63,12 @@ public function testFormatTime($secs, $expectedFormat)
5263
{
5364
$this->assertEquals($expectedFormat, Helper::formatTime($secs));
5465
}
66+
67+
/**
68+
* @dataProvider decoratedTextProvider
69+
*/
70+
public function testRemoveDecoration(string $decoratedText, string $undecoratedText)
71+
{
72+
$this->assertEquals($undecoratedText, Helper::removeDecoration(new OutputFormatter(), $decoratedText));
73+
}
5574
}

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,31 @@ public function testWithColspanAndMaxWith()
15951595
| | | nsectetur |
15961596
+-----------------+-----------------+-----------------+
15971597
1598+
TABLE;
1599+
1600+
$this->assertSame($expected, $this->getOutputContent($output));
1601+
}
1602+
1603+
public function testWithHyperlinkAndMaxWidth()
1604+
{
1605+
$table = new Table($output = $this->getOutputStream(true));
1606+
$table
1607+
->setRows([
1608+
['<href=Lorem>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor</>'],
1609+
])
1610+
;
1611+
$table->setColumnMaxWidth(0, 20);
1612+
$table->render();
1613+
1614+
$expected =
1615+
<<<TABLE
1616+
+----------------------+
1617+
| \033]8;;Lorem\033\\Lorem ipsum dolor si\033]8;;\033\\ |
1618+
| \033]8;;Lorem\033\\t amet, consectetur \033]8;;\033\\ |
1619+
| \033]8;;Lorem\033\\adipiscing elit, sed\033]8;;\033\\ |
1620+
| \033]8;;Lorem\033\\do eiusmod tempor\033]8;;\033\\ |
1621+
+----------------------+
1622+
15981623
TABLE;
15991624

16001625
$this->assertSame($expected, $this->getOutputContent($output));

src/Symfony/Component/ErrorHandler/Resources/bin/extract-tentative-return-types.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
* file that was distributed with this source code.
1111
*/
1212

13+
if ('cli' !== \PHP_SAPI) {
14+
throw new Exception('This script must be run from the command line.');
15+
}
16+
1317
// Run from the root of the php-src repository, this script generates
1418
// a table with all the methods that have a tentative return type.
1519
//

src/Symfony/Component/ErrorHandler/Resources/bin/patch-type-declarations

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
* file that was distributed with this source code.
1111
*/
1212

13+
if ('cli' !== \PHP_SAPI) {
14+
throw new Exception('This script must be run from the command line.');
15+
}
16+
1317
if (\in_array('-h', $argv) || \in_array('--help', $argv)) {
1418
echo implode(PHP_EOL, [
1519
' Patches type declarations based on "@return" PHPDoc and triggers deprecations for',

src/Symfony/Component/ExpressionLanguage/Resources/bin/generate_operator_regex.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
* file that was distributed with this source code.
1010
*/
1111

12+
if ('cli' !== \PHP_SAPI) {
13+
throw new Exception('This script must be run from the command line.');
14+
}
15+
1216
$operators = ['not', '!', 'or', '||', '&&', 'and', '|', '^', '&', '==', '===', '!=', '!==', '<', '>', '>=', '<=', 'not in', 'in', '..', '+', '-', '~', '*', '/', '%', 'matches', '**'];
1317
$operators = array_combine($operators, array_map('strlen', $operators));
1418
arsort($operators);

src/Symfony/Component/Intl/Resources/bin/common.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
* file that was distributed with this source code.
1010
*/
1111

12+
if ('cli' !== \PHP_SAPI) {
13+
throw new Exception('This script must be run from the command line.');
14+
}
15+
1216
define('LINE_WIDTH', 75);
1317

1418
define('LINE', str_repeat('-', LINE_WIDTH)."\n");

src/Symfony/Component/Intl/Resources/bin/update-data.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
use Symfony\Component\Intl\Locale;
2424
use Symfony\Component\Intl\Util\GitRepository;
2525

26+
if ('cli' !== \PHP_SAPI) {
27+
throw new Exception('This script must be run from the command line.');
28+
}
29+
2630
require_once __DIR__.'/common.php';
2731
require_once __DIR__.'/autoload.php';
2832

0 commit comments

Comments
 (0)