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

Skip to content

Commit d849d5d

Browse files
committed
Merge branch '2.2' into 2.3
* 2.2: Throw exception if value is passed to VALUE_NONE input, long syntax fixed date type format pattern regex [FrameworkBundle] tweaked previous merge (refs #8242) do not re-register commands each time a Console\Application is run [Process] moved env check to the Process class (refs #8227) fix issue where $_ENV contains array vals [DomCrawler] Fix handling file:// without a host [Form] corrected interface bind() method defined against in deprecation notice [Finder] Fix SplFileInfo::getContents isn't working with ssh2 protocol Conflicts: src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php src/Symfony/Component/DomCrawler/Link.php src/Symfony/Component/Form/Form.php
2 parents 4dc58ad + 9a76c4f commit d849d5d

File tree

10 files changed

+77
-10
lines changed

10 files changed

+77
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
class Application extends BaseApplication
2828
{
2929
private $kernel;
30+
private $commandsRegistered = false;
3031

3132
/**
3233
* Constructor.
@@ -65,7 +66,11 @@ public function getKernel()
6566
*/
6667
public function doRun(InputInterface $input, OutputInterface $output)
6768
{
68-
$this->registerCommands();
69+
if (!$this->commandsRegistered) {
70+
$this->registerCommands();
71+
72+
$this->commandsRegistered = true;
73+
}
6974

7075
$this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher'));
7176

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private function parseShortOptionSet($name)
134134

135135
break;
136136
} else {
137-
$this->addLongOption($option->getName(), true);
137+
$this->addLongOption($option->getName(), null);
138138
}
139139
}
140140
}
@@ -220,6 +220,10 @@ private function addLongOption($name, $value)
220220
$value = null;
221221
}
222222

223+
if (null !== $value && !$option->acceptValue()) {
224+
throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name, $value));
225+
}
226+
223227
if (null === $value && $option->acceptValue() && count($this->parsed)) {
224228
// if option accepts an optional or mandatory argument
225229
// let's see if there is one provided

src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ public function provideInvalidInput()
175175
new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))),
176176
'The "-o" option does not exist.'
177177
),
178+
array(
179+
array('cli.php', '--foo=bar'),
180+
new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))),
181+
'The "--foo" option does not accept a value.'
182+
),
178183
array(
179184
array('cli.php', 'foo', 'bar'),
180185
new InputDefinition(),

src/Symfony/Component/DomCrawler/Link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function getUri()
125125
return preg_replace('#^([^/]*)//.*$#', '$1', $this->currentUri).$uri;
126126
}
127127

128-
$baseUri = preg_replace('#^(.*?//[^/]+)(?:\/.*)?$#', '$1', $this->currentUri);
128+
$baseUri = preg_replace('#^(.*?//[^/]*)(?:\/.*)?$#', '$1', $this->currentUri);
129129

130130
// absolute path
131131
if ('/' === $uri[0]) {

src/Symfony/Component/DomCrawler/Tests/LinkTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ public function getGetUriTests()
122122
array('../bar/./../../foo', 'http://localhost/bar/foo/', 'http://localhost/foo'),
123123
array('../../', 'http://localhost/', 'http://localhost/'),
124124
array('../../', 'http://localhost', 'http://localhost/'),
125+
126+
array('/foo', 'file:///', 'file:///foo'),
127+
array('/foo', 'file:///bar/baz', 'file:///foo'),
128+
array('foo', 'file:///', 'file:///foo'),
129+
array('foo', 'file:///bar/baz', 'file:///bar/foo'),
125130
);
126131
}
127132
}

src/Symfony/Component/Finder/SplFileInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getRelativePathname()
6565
public function getContents()
6666
{
6767
$level = error_reporting(0);
68-
$content = file_get_contents($this->getRealpath());
68+
$content = file_get_contents($this->getPathname());
6969
error_reporting($level);
7070
if (false === $content) {
7171
$error = error_get_last();

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
144144

145145
// set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
146146
// lookup various formats at http://userguide.icu-project.org/formatparse/datetime
147-
if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $pattern)) {
147+
if (preg_match('/^([yMd]+)[^yMd]*([yMd]+)[^yMd]*([yMd]+)$/', $pattern)) {
148148
$pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
149149
} else {
150150
// default fallback

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,29 @@ public function testSubmitFromInputRawDifferentPattern()
271271
$this->assertEquals('06*2010*02', $form->getViewData());
272272
}
273273

274+
/**
275+
* @dataProvider provideDateFormats
276+
*/
277+
public function testDatePatternWithFormatOption($format, $pattern)
278+
{
279+
$form = $this->factory->create('date', null, array(
280+
'format' => $format,
281+
));
282+
283+
$view = $form->createView();
284+
285+
$this->assertEquals($pattern, $view->vars['date_pattern']);
286+
}
287+
288+
public function provideDateFormats()
289+
{
290+
return array(
291+
array('dMy', '{{ day }}{{ month }}{{ year }}'),
292+
array('d-M-yyyy', '{{ day }}-{{ month }}-{{ year }}'),
293+
array('M d y', '{{ month }} {{ day }} {{ year }}'),
294+
);
295+
}
296+
274297
/**
275298
* This test is to check that the strings '0', '1', '2', '3' are no accepted
276299
* as valid IntlDateFormatter constants for FULL, LONG, MEDIUM or SHORT respectively.

src/Symfony/Component/Process/Process.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin
147147
$this->cwd = getcwd();
148148
}
149149
if (null !== $env) {
150-
$this->env = array();
151-
foreach ($env as $key => $value) {
152-
$this->env[(binary) $key] = (binary) $value;
153-
}
150+
$this->setEnv($env);
154151
} else {
155152
$this->env = null;
156153
}
@@ -942,13 +939,25 @@ public function getEnv()
942939
/**
943940
* Sets the environment variables.
944941
*
942+
* An environment variable value should be a string.
943+
* If it is an array, the variable is ignored.
944+
*
945+
* That happens in PHP when 'argv' is registered into
946+
* the $_ENV array for instance.
947+
*
945948
* @param array $env The new environment variables
946949
*
947950
* @return self The current Process instance
948951
*/
949952
public function setEnv(array $env)
950953
{
951-
$this->env = $env;
954+
// Process can not handle env values that are arrays
955+
$env = array_filter($env, function ($value) { if (!is_array($value)) { return true; } });
956+
957+
$this->env = array();
958+
foreach ($env as $key => $value) {
959+
$this->env[(binary) $key] = (binary) $value;
960+
}
952961

953962
return $this;
954963
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ public function testProcessShouldInheritAndOverrideEnvironmentVars()
4545
$_ENV = $snapshot;
4646
}
4747

48+
public function testProcessBuilderShouldNotPassEnvArrays()
49+
{
50+
$snapshot = $_ENV;
51+
$_ENV = array('a' => array('b', 'c'), 'd' => 'e', 'f' => 'g');
52+
$expected = array('d' => 'e', 'f' => 'g');
53+
54+
$pb = new ProcessBuilder();
55+
$pb->add('a')->inheritEnvironmentVariables()
56+
->setEnv('d', 'e');
57+
$proc = $pb->getProcess();
58+
59+
$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() removes array values from $_ENV');
60+
61+
$_ENV = $snapshot;
62+
}
63+
4864
public function testInheritEnvironmentVarsByDefault()
4965
{
5066
$pb = new ProcessBuilder();

0 commit comments

Comments
 (0)