8000 Merge branch '5.4' into 6.0 · symfony/symfony@8121de6 · GitHub
[go: up one dir, main page]

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

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/mime-db@v1.49.0/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

@@ -588,11 +588,15 @@ private function isNullableProperty(string $class, string $property): bool
588588
return false;
589589
}
590590

591-
private function isAllowedProperty(string $class, string $property): bool
591+
private function isAllowedProperty(string $class, string $property, bool $writeAccessRequired = false): bool
592592
{
593593
try {
594594
$reflectionProperty = new \ReflectionProperty($class, $property);
595595

596+
if (\PHP_VERSION_ID >= 80100 && $writeAccessRequired && $reflectionProperty->isReadOnly()) {
597+
return false;
598+
}
599+
596600
return (bool) ($reflectionProperty->getModifiers() & $this->propertyReflectionFlags);
597601
} catch (\ReflectionException $e) {
598602
// Return false if the property doesn't exist

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php74Dummy;
2626
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php7Dummy;
2727
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php7ParentDummy;
28+
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php81Dummy;
2829
use Symfony\Component\PropertyInfo\Type;
2930

3031
/**
@@ -286,6 +287,7 @@ public function php80TypesProvider()
286287

287288
/**
288289
* @dataProvider php81TypesProvider
290+
*
289291
* @requires PHP 8.1
290292
*/
291293
public function testExtractPhp81Type($property, array $type = null)
@@ -301,8 +303,17 @@ public function php81TypesProvider()
301303
];
302304
}
303305

306+
/**
307+
* @requires PHP 8.1
308+
*/
309+
public function testReadonlyPropertiesAreNotWriteable()
310+
{
311+
$this->assertFalse($this->extractor->isWritable(Php81Dummy::class, 'foo'));
312+
}
313+
304314
/**
305315
* @dataProvider php82TypesProvider
316+
*
306317
* @requires PHP 8.2
307318
*/
308319
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/String/Resources/bin/update-data.php

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

1212
use Symfony\Component\String\Resources\WcswidthDataGenerator;
1313

14+
if ('cli' !== \PHP_SAPI) {
15+
throw new Exception('This script must be run from the command line.');
16+
}
17+
1418
error_reporting(\E_ALL);
1519

1620
set_error_handler(static function (int $type, string $msg, string $file, int $line): void {

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
*

src/Symfony/Component/Yaml/Resources/bin/yaml-lint

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
* Runs the Yaml lint command.
1519
*

0 commit comments

Comments
 (0)
0