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

Skip to content

Commit 3db3ad2

Browse files
Merge branch '4.1'
* 4.1: Remove Process::escapeArgument argument type hint [Console] fix test using deprecated code [travis] build libsodium only if it's not already enabled Add a test case for stringifying of Process arguments 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 Setting missing default paths under BC layer Changed "epost-adress" to "e-postadress" Fix for race condition in console output stream write reverse transform RFC 3339 formatted dates
2 parents e4e6159 + d010eb3 commit 3db3ad2

File tree

11 files changed

+109
-23
lines changed

11 files changed

+109
-23
lines changed

.travis.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,15 @@ before_install:
153153
wget http://ftp.debian.org/debian/pool/main/libr/librabbitmq/librabbitmq1_0.5.2-2_amd64.deb
154154
sudo dpkg -i librabbitmq1_0.5.2-2_amd64.deb librabbitmq-dev_0.5.2-2_amd64.deb
155155
156-
# install libsodium
157-
sudo add-apt-repository ppa:ondrej/php -y
158-
sudo apt-get update -q
159-
sudo apt-get install libsodium-dev -y
156+
if ! php --ri sodium > /dev/null; then
157+
# install libsodium
158+
sudo add-apt-repository ppa:ondrej/php -y
159+
sudo apt-get update -q
160+
sudo apt-get install libsodium-dev -y
161+
tfold ext.libsodium tpecl libsodium sodium.so $INI
162+
fi
160163
161164
tfold ext.apcu tpecl apcu-5.1.6 apcu.so $INI
162-
tfold ext.libsodium tpecl libsodium sodium.so $INI
163165
tfold ext.mongodb tpecl mongodb-1.5.0 mongodb.so $INI
164166
tfold ext.amqp tpecl amqp-1.9.3 amqp.so $INI
165167
tfold ext.igbinary tpecl igbinary-2.0.6 igbinary.so $INI

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

Lines 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

Lines 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

Lines 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

Lines 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+
$inputStream = $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->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
105+
106+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, 'Batman');
107+
$this->assertSame('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
108+
109+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
110+
$this->assertNull($questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, 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->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
115+
116+
try {
117+
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
118+
$questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, 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->createStreamableInputInterfaceMock($inputStream, 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->createStreamableInputInterfaceMock($inputStream, 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->createStreamableInputInterfaceMock($inputStream, 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->createStreamableInputInterfaceMock($inputStream, 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->createStreamableInputInterfaceMock($inputStream, 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

Lines 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

Lines 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/Process/Process.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,14 +1606,14 @@ private function requireProcessIsTerminated(string $functionName)
16061606
/**
16071607
* Escapes a string to be used as a shell argument.
16081608
*/
1609-
private function escapeArgument(string $argument): string
1609+
private function escapeArgument(?string $argument): string
16101610
{
1611+
if ('' === $argument || null === $argument) {
1612+
return '""';
1613+
}
16111614
if ('\\' !== \DIRECTORY_SEPARATOR) {
16121615
return "'".str_replace("'", "'\\''", $argument)."'";
16131616
}
1614-
if ('' === $argument = (string) $argument) {
1615-
return '""';
1616-
}
16171617
if (false !== strpos($argument, "\0")) {
16181618
$argument = str_replace("\0", '?', $argument);
16191619
}

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ public function testEscapeArgument($arg)
14631463
$p = new Process(array(self::$phpBin, '-r', 'echo $argv[1];', $arg));
14641464
$p->run();
14651465

1466-
$this->assertSame($arg, $p->getOutput());
1466+
$this->assertSame((string) $arg, $p->getOutput());
14671467
}
14681468

14691469
public function testRawCommandLine()
@@ -1493,6 +1493,9 @@ public function provideEscapeArgument()
14931493
yield array("a!b\tc");
14941494
yield array('a\\\\"\\"');
14951495
yield array('éÉèÈàÀöä');
1496+
yield array(null);
1497+
yield array(1);
1498+
yield array(1.1);
14961499
}
14971500

14981501
public function testEnvArgument()

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

Lines 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

Lines 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)