Skip to content

Commit 7baeaa2

Browse files
committed
Merge branch '2.4'
* 2.4: [Process] minor fixes Improve performance of getNextEmbedBlock by removing unnecessary preg_match and function calls. Avoid unnecessary line indentation calculation. Optimise Inline::evaluateScalar() for parsing strings. fixed CS fixed parsing Mongo DSN and added Test for it () is also a valid delimiter Adding PHP 5.6 to travis-ci tests Update BCryptPasswordEncoder.php [Validator] Removed PHP <5.3.3 specific code which is not officially supported. Fixed wrong redirect url if path contains some query parameters
2 parents a820930 + 81e27d2 commit 7baeaa2

File tree

11 files changed

+177
-68
lines changed

11 files changed

+177
-68
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ php:
55
- 5.3
66
- 5.4
77
- 5.5
8+
- 5.6
89
- hhvm
910

1011
matrix:

src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ public function urlRedirectAction(Request $request, $path, $permanent = false, $
100100

101101
$qs = $request->getQueryString();
102102
if ($qs) {
103-
$qs = '?'.$qs;
103+
if (strpos($path, '?') === false) {
104+
$qs = '?'.$qs;
105+
} else {
106+
$qs = '&'.$qs;
107+
}
104108
}
105109

106110
$port = '';

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,36 @@ public function testUrlRedirect($scheme, $httpPort, $httpsPort, $requestScheme,
199199
$this->assertRedirectUrl($returnValue, $expectedUrl);
200200
}
201201

202-
private function createRequestObject($scheme, $host, $port, $baseUrl)
202+
public function pathQueryParamsProvider()
203+
{
204+
return array(
205+
array('http://www.example.com/base/redirect-path', '/redirect-path', ''),
206+
array('http://www.example.com/base/redirect-path?foo=bar', '/redirect-path?foo=bar', ''),
207+
array('http://www.example.com/base/redirect-path?foo=bar', '/redirect-path', 'foo=bar'),
208+
array('http://www.example.com/base/redirect-path?foo=bar&abc=example', '/redirect-path?foo=bar', 'abc=example'),
209+
array('http://www.example.com/base/redirect-path?foo=bar&abc=example&baz=def', '/redirect-path?foo=bar', 'abc=example&baz=def'),
210+
);
211+
}
212+
213+
/**
214+
* @dataProvider pathQueryParamsProvider
215+
*/
216+
public function testPathQueryParams($expectedUrl, $path, $queryString)
217+
{
218+
$scheme = 'http';
219+
$host = 'www.example.com';
220+
$baseUrl = '/base';
221+
$port = 80;
222+
223+
$request = $this->createRequestObject($scheme, $host, $port, $baseUrl, $queryString);
224+
225+
$controller = $this->createRedirectController();
226+
227+
$returnValue = $controller->urlRedirectAction($request, $path, false, $scheme, $port, null);
228+
$this->assertRedirectUrl($returnValue, $expectedUrl);
229+
}
230+
231+
private function createRequestObject($scheme, $host, $port, $baseUrl, $queryString = '')
203232
{
204233
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
205234
$request
@@ -218,6 +247,10 @@ private function createRequestObject($scheme, $host, $port, $baseUrl)
218247
->expects($this->any())
219248
->method('getBaseUrl')
220249
->will($this->returnValue($baseUrl));
250+
$request
251+
->expects($this->any())
252+
->method('getQueryString')
253+
->will($this->returnValue($queryString));
221254

222255
return $request;
223256
}

src/Symfony/Component/Finder/Expression/Regex.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ public static function create($expr)
6565
$start = substr($m[1], 0, 1);
6666
$end = substr($m[1], -1);
6767

68-
if (($start === $end && !preg_match('/[*?[:alnum:] \\\\]/', $start)) || ($start === '{' && $end === '}')) {
68+
if (
69+
($start === $end && !preg_match('/[*?[:alnum:] \\\\]/', $start))
70+
|| ($start === '{' && $end === '}')
71+
|| ($start === '(' && $end === ')')
72+
) {
6973
return new self(substr($m[1], 1, -1), $m[2], $end);
7074
}
7175
}

src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,19 @@ public function write(Profile $profile)
9999
*/
100100
protected function getMongo()
101101
{
102-
if ($this->mongo === null) {
103-
if (preg_match('#^(mongodb://.*)/(.*)/(.*)$#', $this->dsn, $matches)) {
104-
$server = $matches[1].(!empty($matches[2]) ? '/'.$matches[2] : '');
105-
$database = $matches[2];
106-
$collection = $matches[3];
107-
108-
$mongoClass = (version_compare(phpversion('mongo'), '1.3.0', '<')) ? '\Mongo' : '\MongoClient';
109-
$mongo = new $mongoClass($server);
110-
$this->mongo = $mongo->selectCollection($database, $collection);
111-
} else {
112-
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use MongoDB with an invalid dsn "%s". The expected format is "mongodb://[user:pass@]host/database/collection"', $this->dsn));
113-
}
102+
if (null !== $this->mongo) {
103+
return $this->mongo;
104+
}
105+
106+
if (!$parsedDsn = $this->parseDsn($this->dsn)) {
107+
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use MongoDB with an invalid dsn "%s". The expected format is "mongodb://[user:pass@]host/database/collection"', $this->dsn));
114108
}
115109

116-
return $this->mongo;
110+
list($server, $database, $collection) = $parsedDsn;
111+
$mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? '\Mongo' : '\MongoClient';
112+
$mongo = new $mongoClass($server);
113+
114+
return $this->mongo = $mongo->selectCollection($database, $collection);
117115
}
118116

119117
/**
@@ -233,4 +231,27 @@ private function getProfile(array $data)
233231

234232
return $profile;
235233
}
234+
235+
/**
236+
* @param string $dsn
237+
*
238+
* @return null|array Array($server, $database, $collection)
239+
*/
240+
private function parseDsn($dsn)
241+
{
242+
if (!preg_match('#^(mongodb://.*)/(.*)/(.*)$#', $dsn, $matches)) {
243+
return;
244+
}
245+
246+
$server = $matches[1];
247+
$database = $matches[2];
248+
$collection = $matches[3];
249+
preg_match('#^mongodb://(([^:]+):?(.*)(?=@))?@?([^/]*)(.*)$#', $server, $matchesServer);
250+
251+
if ('' == $matchesServer[5] && '' != $matches[2]) {
252+
$server .= '/'.$matches[2];
253+
}
254+
255+
return array($server, $database, $collection);
256+
}
236257
}

src/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,32 @@ public static function tearDownAfterClass()
7171
}
7272
}
7373

74+
public function getDsns()
75+
{
76+
return array(
77+
array('mongodb://localhost/symfony_tests/profiler_data', array(
78+
'mongodb://localhost/symfony_tests',
79+
'symfony_tests',
80+
'profiler_data'
81+
)),
82+
array('mongodb://user:password@localhost/symfony_tests/profiler_data', array(
83+
'mongodb://user:password@localhost/symfony_tests',
84+
'symfony_tests',
85+
'profiler_data'
86+
)),
87+
array('mongodb://user:password@localhost/admin/symfony_tests/profiler_data', array(
88+
'mongodb://user:password@localhost/admin',
89+
'symfony_tests',
90+
'profiler_data'
91+
)),
92+
array('mongodb://user:password@localhost:27009,localhost:27010/?replicaSet=rs-name&authSource=admin/symfony_tests/profiler_data', array(
93+
'mongodb://user:password@localhost:27009,localhost:27010/?replicaSet=rs-name&authSource=admin',
94+
'symfony_tests',
95+
'profiler_data'
96+
))
97+
);
98+
}
99+
74100
public function testCleanup()
75101
{
76102
$dt = new \DateTime('-2 day');
@@ -87,6 +113,17 @@ public function testCleanup()
87113
self::$storage->purge();
88114
}
89115

116+
/**
117+
* @dataProvider getDsns
118+
*/
119+
public function testDsnParser($dsn, $expected)
120+
{
121+
$m = new \ReflectionMethod(self::$storage, 'parseDsn');
122+
$m->setAccessible(true);
123+
124+
$this->assertEquals($expected, $m->invoke(self::$storage, $dsn));
125+
}
126+
90127
public function testUtf8()
91128
{
92129
$profile = new Profile('utf8_test_profile');

src/Symfony/Component/Process/Process.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,9 @@ public function getEnv()
911911
public function setEnv(array $env)
912912
{
913913
// Process can not handle env values that are arrays
914-
$env = array_filter($env, function ($value) { if (!is_array($value)) { return true; } });
914+
$env = array_filter($env, function ($value) {
915+
return !is_array($value);
916+
});
915917

916918
$this->env = array();
917919
foreach ($env as $key => $value) {
@@ -1190,6 +1192,7 @@ private function validateTimeout($timeout)
11901192
* Reads pipes, executes callback.
11911193
*
11921194
* @param Boolean $blocking Whether to use blocking calls or not.
1195+
* @param Boolean $close Whether to close file handles or not.
11931196
*/
11941197
private function readPipes($blocking, $close)
11951198
{

src/Symfony/Component/Process/ProcessPipes.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function unblock()
7979
public function close()
8080
{
8181
$this->closeUnixPipes();
82-
foreach ($this->fileHandles as $offset => $handle) {
82+
foreach ($this->fileHandles as $handle) {
8383
fclose($handle);
8484
}
8585
$this->fileHandles = array();
@@ -227,6 +227,8 @@ public function write($blocking, $stdin)
227227
/**
228228
* Reads data in file handles.
229229
*
230+
* @param Boolean $close Whether to close file handles or not.
231+
*
230232
* @return array An array of read data indexed by their fd.
231233
*/
232234
private function readFileHandles($close = false)
@@ -262,6 +264,7 @@ private function readFileHandles($close = false)
262264
* Reads data in file pipes streams.
263265
*
264266
* @param Boolean $blocking Whether to use blocking calls or not.
267+
* @param Boolean $close Whether to close file handles or not.
265268
*
266269
* @return array An array of read data indexed by their fd.
267270
*/

src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class BCryptPasswordEncoder extends BasePasswordEncoder
2929
*
3030
* @param integer $cost The algorithmic cost that should be used
3131
*
32+
* @throws \RuntimeException When no BCrypt encoder is available
3233
* @throws \InvalidArgumentException if cost is out of range
3334
*/
3435
public function __construct($cost)

src/Symfony/Component/Yaml/Inline.php

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -386,51 +386,55 @@ private static function parseMapping($mapping, &$i = 0)
386386
private static function evaluateScalar($scalar)
387387
{
388388
$scalar = trim($scalar);
389-
389+
$scalarLower = strtolower($scalar);
390390
switch (true) {
391-
case 'null' == strtolower($scalar):
391+
case 'null' == $scalarLower:
392392
case '' == $scalar:
393393
case '~' == $scalar:
394394
return null;
395-
case 0 === strpos($scalar, '!str'):
396-
return (string) substr($scalar, 5);
397-
case 0 === strpos($scalar, '! '):
398-
return intval(self::parseScalar(substr($scalar, 2)));
399-
case 0 === strpos($scalar, '!!php/object:'):
400-
if (self::$objectSupport) {
401-
return unserialize(substr($scalar, 13));
402-
}
403-
404-
if (self::$exceptionOnInvalidType) {
405-
throw new ParseException('Object support when parsing a YAML file has been disabled.');
406-
}
407-
408-
return null;
409-
case ctype_digit($scalar):
410-
$raw = $scalar;
411-
$cast = intval($scalar);
412-
413-
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
414-
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
415-
$raw = $scalar;
416-
$cast = intval($scalar);
417-
418-
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
419-
case 'true' === strtolower($scalar):
395+
case 'true' === $scalarLower:
420396
return true;
421-
case 'false' === strtolower($scalar):
397+
case 'false' === $scalarLower:
422398
return false;
423-
case is_numeric($scalar):
424-
return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar);
425-
case 0 == strcasecmp($scalar, '.inf'):
426-
case 0 == strcasecmp($scalar, '.NaN'):
427-
return -log(0);
428-
case 0 == strcasecmp($scalar, '-.inf'):
429-
return log(0);
430-
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar):
431-
return floatval(str_replace(',', '', $scalar));
432-
case preg_match(self::getTimestampRegex(), $scalar):
433-
return strtotime($scalar);
399+
// Optimise for returning strings.
400+
case $scalar[0] === '+' || $scalar[0] === '-' || $scalar[0] === '.' || $scalar[0] === '!' || is_numeric($scalar[0]):
401+
switch (true) {
402+
case 0 === strpos($scalar, '!str'):
403+
return (string) substr($scalar, 5);
404+
case 0 === strpos($scalar, '! '):
405+
return intval(self::parseScalar(substr($scalar, 2)));
406+
case 0 === strpos($scalar, '!!php/object:'):
407+
if (self::$objectSupport) {
408+
return unserialize(substr($scalar, 13));
409+
}
410+
411+
if (self::$exceptionOnInvalidType) {
412+
throw new ParseException('Object support when parsing a YAML file has been disabled.');
413+
}
414+
415+
return null;
416+
case ctype_digit($scalar):
417+
$raw = $scalar;
418+
$cast = intval($scalar);
419+
420+
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
421+
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
422+
$raw = $scalar;
423+
$cast = intval($scalar);
424+
425+
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
426+
case is_numeric($scalar):
427+
return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar);
428+
case 0 == strcasecmp($scalar, '.inf'):
429+
case 0 == strcasecmp($scalar, '.NaN'):
430+
return -log(0);
431+
case 0 == strcasecmp($scalar, '-.inf'):
432+
return log(0);
433+
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar):
434+
return floatval(str_replace(',', '', $scalar));
435+
case preg_match(self::getTimestampRegex(), $scalar):
436+
return strtotime($scalar);
437+
}
434438
default:
435439
return (string) $scalar;
436440
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy