8000 Merge branch '4.4' into 5.3 · adamwojs/symfony@e108a7f · GitHub
[go: up one dir, main page]

Skip to content

Commit e108a7f

Browse files
Merge branch '4.4' into 5.3
* 4.4: [Cache] workaround PHP crash [Console] Fix PHP 8.1 deprecation in ChoiceQuestion Making the parser stateless
2 parents 1199672 + 256ce7f commit e108a7f

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

src/Symfony/Component/Cache/Traits/ContractsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ trait ContractsTrait
4242
public function setCallbackWrapper(?callable $callbackWrapper): callable
4343
{
4444
if (!isset($this->callbackWrapper)) {
45-
$this->callbackWrapper = \Closure::fromCallable([LockRegistry::class, 'compute']);
45+
$this->callbackWrapper = [LockRegistry::class, 'compute'];
4646

4747
if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
4848
$this->setCallbackWrapper(null);

src/Symfony/Component/Console/Question/ChoiceQuestion.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,18 @@ private function getDefaultValidator(): callable
125125
return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) {
126126
if ($multiselect) {
127127
// Check for a separated comma values
128-
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) {
128+
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', (string) $selected, $matches)) {
129129
throw new InvalidArgumentException(sprintf($errorMessage, $selected));
130130
}
131131

132-
$selectedChoices = explode(',', $selected);
132+
$selectedChoices = explode(',', (string) $selected);
133133
} else {
134134
$selectedChoices = [$selected];
135135
}
136136

137137
if ($this->isTrimmable()) {
138138
foreach ($selectedChoices as $k => $v) {
139-
$selectedChoices[$k] = trim($v);
139+
$selectedChoices[$k] = trim((string) $v);
140140
}
141141
}
142142

src/Symfony/Component/Console/Tests/Question/ChoiceQuestionTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ class ChoiceQuestionTest extends TestCase
1919
/**
2020
* @dataProvider selectUseCases
2121
*/
22-
public function testSelectUseCases($multiSelect, $answers, $expected, $message)
22+
public function testSelectUseCases($multiSelect, $answers, $expected, $message, $default = null)
2323
{
2424
$question = new ChoiceQuestion('A question', [
2525
'First response',
2626
'Second response',
2727
'Third response',
2828
'Fourth response',
29-
]);
29+
null,
30+
], $default);
3031

3132
$question->setMultiselect($multiSelect);
3233

@@ -59,6 +60,19 @@ public function selectUseCases()
5960
['First response', 'Second response'],
6061
'When passed multiple answers on MultiSelect, the defaultValidator must return these answers as an array',
6162
],
63+
[
64+
false,
65+
[null],
66+
null,
67+
'When used null as default single answer on singleSelect, the defaultValidator must return this answer as null',
68+
],
69+
[
70+
false,
71+
['First response'],
72+
'First response',
73+
'When used a string as default single answer on singleSelect, the defaultValidator must return this answer as a string',
74+
'First response',
75+
],
6276
[
6377
false,
6478
[0],

src/Symfony/Component/Yaml/Parser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public function parse(string $value, int $flags = 0)
9999
if (null !== $mbEncoding) {
100100
mb_internal_encoding($mbEncoding);
101101
}
102+
$this->refsBeingParsed = [];
103+
$this->offset = 0;
102104
$this->lines = [];
103105
$this->currentLine = '';
104106
$this->numberOfParsedLines = 0;

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ public function invalidIndentation(): array
8484
];
8585
}
8686

87+
public function testParserIsStateless()
88+
{
89+
$yamlString = '# translations/messages.en.yaml
90+
91+
';
92+
$this->parser->parse($yamlString);
93+
$this->parser->parse($yamlString);
94+
95+
$this->expectException(ParseException::class);
96+
$this->expectExceptionMessage("A YAML file cannot contain tabs as indentation at line 2 (near \"\tabc\")");
97+
98+
$this->parser->parse("abc:\n\tabc");
99+
}
100+
87101
/**
88102
* @dataProvider validTokenSeparators
89103
*/

0 commit comments

Comments
 (0)
0