Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a5792bf

Browse filesBrowse files
Merge branch '2.8' into 3.4
* 2.8: Add a missing English translation [Console] Fixes multiselect choice question in interactive mode with default values [Validator] Add a missing Polish translation Allow integers as default console option value Changed "epost-adress" to "e-postadress" Fix for race condition in console output stream write reverse transform RFC 3339 formatted dates
2 parents f89ef42 + c6b288e commit a5792bf
Copy full SHA for a5792bf

File tree

Expand file treeCollapse file tree

9 files changed

+98
-13
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+98
-13
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/QuestionHelper.php
+13-3Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,23 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
4747
}
4848

4949
if (!$input->isInteractive()) {
50-
if ($question instanceof ChoiceQuestion) {
50+
$default = $question->getDefault();
51+
52+
if (null !== $default && $question instanceof ChoiceQuestion) {
5153
$choices = $question->getChoices();
5254

53-
return $choices[$question->getDefault()];
55+
if (!$question->isMultiselect()) {
56+
return isset($choices[$default]) ? $choices[$default] : $default;
57+
}
58+
59+
$default = explode(',', $default);
60+
foreach ($default as $k => $v) {
61+
$v = trim($v);
62+
$default[$k] = isset($choices[$v]) ? $choices[$v] : $v;
63+
}
5464
}
5565

56-
return $question->getDefault();
66+
return $default;
5767
}
5868

5969
if ($input instanceof StreamableInputInterface && $stream = $input->getStream()) {

‎src/Symfony/Component/Console/Input/InputOption.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Input/InputOption.php
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class InputOption
3333
private $description;
3434

3535
/**
36-
* @param string $name The option name
37-
* @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
38-
* @param int|null $mode The option mode: One of the VALUE_* constants
39-
* @param string $description A description text
40-
* @param string|string[]|bool|null $default The default value (must be null for self::VALUE_NONE)
36+
* @param string $name The option name
37+
* @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
38+
* @param int|null $mode The option mode: One of the VALUE_* constants
39+
* @param string $description A description text
40+
* @param string|string[]|int|bool|null $default The default value (must be null for self::VALUE_NONE)
4141
*
4242
* @throws InvalidArgumentException If option mode is invalid or incompatible
4343
*/
@@ -149,7 +149,7 @@ public function isArray()
149149
/**
150150
* Sets the default value.
151151
*
152-
* @param string|string[]|bool|null $default The default value
152+
* @param string|string[]|int|bool|null $default The default value
153153
*
154154
* @throws LogicException When incorrect default value is given
155155
*/
@@ -173,7 +173,7 @@ public function setDefault($default = null)
173173
/**
174174
* Returns the default value.
175175
*
176-
* @return string|string[]|bool|null The default value
176+
* @return string|string[]|int|bool|null The default value
177177
*/
178178
public function getDefault()
179179
{

‎src/Symfony/Component/Console/Output/StreamOutput.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Output/StreamOutput.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ public function getStream()
7070
*/
7171
protected function doWrite($message, $newline)
7272
{
73-
if (false === @fwrite($this->stream, $message) || ($newline && (false === @fwrite($this->stream, PHP_EOL)))) {
73+
if ($newline) {
74+
$message .= PHP_EOL;
75+
}
76+
77+
if (false === @fwrite($this->stream, $message)) {
7478
// should never happen
7579
throw new RuntimeException('Unable to write output.');
7680
}

‎src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,63 @@ public function testAskChoice()
8989
$this->assertEquals('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, true), $this->createOutputInterface(), $question));
9090
}
9191

92+
public function testAskChoiceNonInteractive()
93+
{
94+
$questionHelper = new QuestionHelper();
95+
96+
$helperSet = new HelperSet(array(new FormatterHelper()));
97+
$questionHelper->setHelperSet($helperSet);
98+
$questionHelper->setInputStream($this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n"));
99+
100+
$heroes = array('Superman', 'Batman', 'Spiderman');
101+
102+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0');
103+
104+
$this->assertSame('Superman', $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
105+
106+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, 'Batman');
107+
$this->assertSame('Batman', $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
108+
109+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
110+
$this->assertNull($questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
111+
112+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0');
113+
$question->setValidator(null);
114+
$this->assertSame('Superman', $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
115+
116+
try {
117+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
118+
$questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question);
119+
} catch (\InvalidArgumentException $e) {
120+
$this->assertSame('Value "" is invalid', $e->getMessage());
121+
}
122+
123+
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, 1');
124+
$question->setMultiselect(true);
125+
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
126+
127+
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, 1');
128+
$question->setMultiselect(true);
129+
$question->setValidator(null);
130+
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
131+
132+
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, Batman');
133+
$question->setMultiselect(true);
134+
$this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
135+
136+
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, null);
137+
$question->setMultiselect(true);
138+
$this->assertNull($questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question));
139+
140+
try {
141+
$question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '');
142+
$question->setMultiselect(true);
143+
$questionHelper->ask($this->createInputInterfaceMock(false), $this->createOutputInterface(), $question);
144+
} catch (\InvalidArgumentException $e) {
145+
$this->assertSame('Value "" is invalid', $e->getMessage());
146+
}
147+
}
148+
92149
public function testAsk()
93150
{
94151
$dialog = new QuestionHelper();

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformer.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ public function reverseTransform($dateTimeLocal)
8181
return;
8282
}
8383

84-
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?$/', $dateTimeLocal, $matches)) {
84+
// to maintain backwards compatibility we do not strictly validate the submitted date
85+
// see https://github.com/symfony/symfony/issues/28699
86+
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?/', $dateTimeLocal, $matches)) {
8587
throw new TransformationFailedException(sprintf('The date "%s" is not a valid date.', $dateTimeLocal));
8688
}
8789

‎src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformerTest.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public function reverseTransformProvider()
5151
array('UTC', 'UTC', '2010-02-03 04:05:00 UTC', '2010-02-03T04:05'),
5252
array('America/New_York', 'Asia/Hong_Kong', '2010-02-03 04:05:00 America/New_York', '2010-02-03T17:05'),
5353
array('Europe/Amsterdam', 'Europe/Amsterdam', '2013-08-21 10:30:00 Europe/Amsterdam', '2013-08-21T10:30:00'),
54+
array('UTC', 'UTC', '2018-09-15T10:00:00Z', '2018-09-15T10:00:00Z'),
55+
array('Europe/Berlin', 'Europe/Berlin', '2018-09-15T10:00:00+02:00', '2018-09-15T10:00:00+02:00'),
56+
array('Europe/Berlin', 'Europe/Berlin', '2018-09-15T10:00:00+0200', '2018-09-15T10:00:00+0200'),
57+
array('UTC', 'UTC', '2018-10-03T10:00:00.000Z', '2018-10-03T10:00:00.000Z'),
5458
);
5559
}
5660

‎src/Symfony/Component/Validator/Resources/translations/validators.en.xlf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Resources/translations/validators.en.xlf
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@
322322
<source>This is not a valid UUID.</source>
323323
<target>This is not a valid UUID.</target>
324324
</trans-unit>
325+
<trans-unit id="84">
326+
<source>This value should be a multiple of {{ compared_value }}.</source>
327+
<target>This value should be a multiple of {{ compared_value }}.</target>
328+
</trans-unit>
325329
</body>
326330
</file>
327331
</xliff>

‎src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@
322322
<source>This is not a valid UUID.</source>
323323
<target>To nie jest poprawne UUID.</target>
324324
</trans-unit>
325+
<trans-unit id="84">
326+
<source>This value should be a multiple of {{ compared_value }}.</source>
327+
<target>Ta wartość powinna być wielokrotnością {{ compared_value }}.</target>
328+
</trans-unit>
325329
</body>
326330
</file>
327331
</xliff>

‎src/Symfony/Component/Validator/Resources/translations/validators.sv.xlf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Resources/translations/validators.sv.xlf
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
</trans-unit>
5353
<trans-unit id="13">
5454
<source>This value is not a valid email address.</source>
55-
<target>Värdet är inte en giltig epost-adress.</target>
55+
<target>Värdet är inte en giltig e-postadress.</target>
5656
</trans-unit>
5757
<trans-unit id="14">
5858
<source>The file could not be found.</source>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.