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

Skip to content

Commit e9607d0

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

File tree

14 files changed

+100
-2
lines changed

14 files changed

+100
-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
@@ -171,6 +171,8 @@ public static function removeDecoration(OutputFormatterInterface $formatter, ?st
171171
$string = $formatter->format($string ?? '');
172172
// remove already formatted characters
173173
$string = preg_replace("/\033\[[^m]*m/", '', $string ?? '');
174+
// remove terminal hyperlinks
175+
$string = preg_replace('/\\033]8;[^;]*;[^\\033]*\\033\\\\/', '', $string ?? '');
174176
$formatter->setDecorated($isDecorated);
175177

176178
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/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

src/Symfony/Component/Mime/Resources/bin/update_mime_types.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
// load new map
1317
$data = json_decode(file_get_contents('https://cdn.jsdelivr.net/gh/jshttp/[email protected]/db.json'), true);
1418
$new = [];

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function isReadable(string $class, string $property, array $context = [])
218218
*/
219219
public function isWritable(string $class, string $property, array $context = []): ?bool
220220
{
221-
if ($this->isAllowedProperty($class, $property)) {
221+
if ($this->isAllowedProperty($class, $property, true)) {
222222
return true;
223223
}
224224

@@ -608,11 +608,15 @@ private function isNullableProperty(string $class, string $property): bool
608608
return false;
609609
}
610610

611-
private function isAllowedProperty(string $class, string $property): bool
611+
private function isAllowedProperty(string $class, string $property, bool $writeAccessRequired = false): bool
612612
{
613613
try {
614614
$reflectionProperty = new \ReflectionProperty($class, $property);
615615

616+
if (\PHP_VERSION_ID >= 80100 && $writeAccessRequired && $reflectionProperty->isReadOnly()) {
617+
return false;
618+
}
619+
616620
return (bool) ($reflectionProperty->getModifiers() & $this->propertyReflectionFlags);
617621
} catch (\ReflectionException $e) {
618622
// Return false if the property doesn't exist

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php74Dummy;
2727
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy;
2828
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php7ParentDummy;
29+
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php81Dummy;
2930
use Symfony\Component\PropertyInfo\Type;
3031

3132
/**
@@ -267,6 +268,7 @@ public function php71TypesProvider()
267268

268269
/**
269270
* @dataProvider php80TypesProvider
271+
*
270272
* @requires PHP 8
271273
*/
272274
public function testExtractPhp80Type($property, array $type = null)
@@ -290,6 +292,7 @@ public function php80TypesProvider()
290292

291293
/**
292294
* @dataProvider php81TypesProvider
295+
*
293296
* @requires PHP 8.1
294297
*/
295298
public function testExtractPhp81Type($property, array $type = null)
@@ -305,8 +308,17 @@ public function php81TypesProvider()
305308
];
306309
}
307310

311+
/**
312+
* @requires PHP 8.1
313+
*/
314+
public function testReadonlyPropertiesAreNotWriteable()
315+
{
316+
$this->assertFalse($this->extractor->isWritable(Php81Dummy::class, 'foo'));
317+
}
318+
308319
/**
309320
* @dataProvider php82TypesProvider
321+
*
310322
* @requires PHP 8.2
311323
*/
312324
public function testExtractPhp82Type($property, array $type = null)

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
class Php81Dummy
1515
{
16+
public function __construct(public readonly string $foo)
17+
{
18+
}
19+
1620
public function getNothing(): never
1721
{
1822
throw new \Exception('Oops');

src/Symfony/Component/Translation/Resources/bin/translation-status.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
$usageInstructions = <<<END
1317
1418
Usage instructions

src/Symfony/Component/VarDumper/Resources/bin/var-dump-server

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
/**
1418
* Starts a dump server to collect and output dumps on a single place with multiple formats support.
1519
*

0 commit comments

Comments
 (0)