10000 Merge branch '2.1' into 2.2 · symfony/symfony@7c66dff · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c66dff

Browse files
committed
Merge branch '2.1' into 2.2
* 2.1: [FrameworkBundle] Fix code status in dockblock Fixed test to use Reflection [Finder] fixed a potential issue on Solaris where INF value is wrong (refs #7269) Update RouteCompiler.php [FrameworkBundle] avoids cache:clear to break if new/old folders already exist [HttpKernel] Fixed possible profiler token collision (closes #7272, closes #7171) [ClassLoader] tweaked test [ClassLoader] made DebugClassLoader idempotent [DomCrawler] Fix relative path handling in links Conflicts: src/Symfony/Component/DomCrawler/Link.php src/Symfony/Component/Finder/Iterator/DepthRangeFilterIterator.php src/Symfony/Component/Routing/RouteCompiler.php
2 parents b7a85e0 + a27f7d8 commit 7c66dff

File tree

9 files changed

+124
-14
lines changed

9 files changed

+124
-14
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,32 @@ protected function execute(InputInterface $input, OutputInterface $output)
6262
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
6363
}
6464

65+
$filesystem = $this->getContainer()->get('filesystem');
6566
$kernel = $this->getContainer()->get('kernel');
6667
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
6768

6869
$this->getContainer()->get('cache_clearer')->clear($realCacheDir);
6970

71+
if ($filesystem->exists($oldCacheDir)) {
72+
$filesystem->remove($oldCacheDir);
73+
}
74+
7075
if ($input->getOption('no-warmup')) {
71-
rename($realCacheDir, $oldCacheDir);
76+
$filesystem->rename($realCacheDir, $oldCacheDir);
7277
} else {
7378
$warmupDir = $realCacheDir.'_new';
7479

80+
if ($filesystem->exists($warmupDir)) {
81+
$filesystem->remove($warmupDir);
82+
}
83+
7584
$this->warmup($warmupDir, !$input->getOption('no-optional-warmers'));
7685

77-
rename($realCacheDir, $oldCacheDir);
78-
rename($warmupDir, $realCacheDir);
86+
$filesystem->rename($realCacheDir, $oldCacheDir);
87+
$filesystem->rename($warmupDir, $realCacheDir);
7988
}
8089

81-
$this->getContainer()->get('filesystem')->remove($oldCacheDir);
90+
$filesystem->remove($oldCacheDir);
8291
}
8392

8493
protected function warmup($warmupDir, $enableOptionalWarmers = true)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class RedirectController extends ContainerAware
2626
/**
2727
* Redirects to another route with the given name.
2828
*
29-
* The response status code is 301 if the permanent parameter is false (default),
30-
* and 302 if the redirection is permanent.
29+
* The response status code is 302 if the permanent parameter is false (default),
30+
* and 301 if the redirection is permanent.
3131
*
3232
* In case the route name is empty, the status code will be 404 when permanent is false
3333
* and 410 otherwise.
@@ -52,8 +52,8 @@ public function redirectAction($route, $permanent = false)
5252
/**
5353
* Redirects to a URL.
5454
*
55-
* The response status code is 301 if the permanent parameter is false (default),
56-
* and 302 if the redirection is permanent.
55+
* The response status code is 302 if the permanent parameter is false (default),
56+
* and 301 if the redirection is permanent.
5757
*
5858
* In case the path is empty, the status code will be 404 when permanent is false
5959
* and 410 otherwise.

src/Symfony/Component/ClassLoader/DebugClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function enable()
5353
}
5454

5555
foreach ($functions as $function) {
56-
if (is_array($function) && method_exists($function[0], 'findFile')) {
56+
if (is_array($function) && !$function[0] instanceof self && method_exists($function[0], 'findFile')) {
5757
$function = array(new static($function[0]), 'loadClass');
5858
}
5959

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\ClassLoader\Tests;
13+
14+
use Symfony\Component\ClassLoader\ClassLoader;
15+
use Symfony\Component\ClassLoader\DebugClassLoader;
16+
17+
class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase
18+
{
19+
private $loader;
20+
21+
protected function setUp()
22+
{
23+
$this->loader = new ClassLoader();
24+
spl_autoload_register(array($this->loader, 'loadClass'));
25+
}
26+
27+
protected function tearDown()
28+
{
29+
spl_autoload_unregister(array($this->loader, 'loadClass'));
30+
}
31+
32+
public function testIdempotence()
33+
{
34+
DebugClassLoader::enable();
35+
DebugClassLoader::enable();
36+
37+
$functions = spl_autoload_functions();
38+
foreach ($functions as $function) {
39+
if (is_array($function) && $function[0] instanceof DebugClassLoader) {
40+
$reflClass = new \ReflectionClass($function[0]);
41+
$reflProp = $reflClass->getProperty('classFinder');
42+
$reflProp->setAccessible(true);
43+
44+
$this->assertNotInstanceOf('Symfony\Component\ClassLoader\DebugClassLoader', $reflProp->getValue($function[0]));
45+
return;
46+
}
47+
}
48+
49+
throw new \Exception('DebugClassLoader did not register');
50+
}
51+
}

src/Symfony/Component/DomCrawler/Link.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,18 @@ public function getUri()
120120
return $baseUri.$uri;
121121
}
122122

123+
$baseUri = preg_replace('#^(.*?//[^/]+)(?:\/.*)?$#', '$1', $this->currentUri);
124+
123125
// absolute path
124126
if ('/' === $uri[0]) {
125-
return preg_replace('#^(.*?//[^/]+)(?:\/.*)?$#', '$1', $this->currentUri).$uri;
127+
return $baseUri.$uri;
126128
}
127129

128130
// relative path
129-
return substr($this->currentUri, 0, strrpos($this->currentUri, '/') + 1).$uri;
131+
$path = parse_url(substr($this->currentUri, strlen($baseUri)), PHP_URL_PATH);
132+
$path = $this->canonicalizePath(substr($path, 0, strrpos($path, '/')).'/'.$uri);
133+
134+
return $baseUri.('' === $path || '/' !== $path[0] ? '/' : '').$path;
130135
}
131136

132137
/**
@@ -139,6 +144,36 @@ protected function getRawUri()
139144
return $this->node->getAttribute('href');
140145
}
141146

147+
/**
148+
* Returns the canonicalized URI path (see RFC 3986, section 5.2.4)
149+
*
150+
* @param string $path URI path
151+
*
152+
* @return string
153+
*/
154+
protected function canonicalizePath($path)
155+
{
156+
if ('' === $path || '/' === $path) {
157+
return $path;
158+
}
159+
160+
if ('.' === substr($path, -1)) {
161+
$path = $path.'/';
162+
}
163+
164+
$output = array();
165+
166+
foreach (explode('/', $path) as $segment) {
167+
if ('..' === $segment) {
168+
array_pop($output);
169+
} elseif ('.' !== $segment) {
170+
array_push($output, $segment);
171+
}
172+
}
173+
174+
return implode('/', $output);
175+
}
176+
142177
/**
143178
* Sets current \DOMNode instance.
144179
*

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ public function getGetUriTests()
101101
array('?foo=2', 'http://localhost/bar?foo=1', 'http://localhost/bar?foo=2'),
102102
array('?foo=2', 'http://localhost/bar/?foo=1', 'http://localhost/bar/?foo=2'),
103103
array('?bar=2', 'http://localhost?foo=1', 'http://localhost?bar=2'),
104+
105+
array('.', 'http://localhost/foo/bar/baz', 'http://localhost/foo/bar/'),
106+
array('./', 'http://localhost/foo/bar/baz', 'http://localhost/foo/bar/'),
107+
array('./foo', 'http://localhost/foo/bar/baz', 'http://localhost/foo/bar/foo'),
108+
array('..', 'http://localhost/foo/bar/baz', 'http://localhost/foo/'),
109+
array('../', 'http://localhost/foo/bar/baz', 'http://localhost/foo/'),
110+
array('../foo', 'http://localhost/foo/bar/baz', 'http://localhost/foo/foo'),
111+
array('../..', 'http://localhost/foo/bar/baz', 'http://localhost/'),
112+
array('../../', 'http://localhost/foo/bar/baz', 'http://localhost/'),
113+
array('../../foo', 'http://localhost/foo/bar/baz', 'http://localhost/foo'),
114+
array('../../foo', 'http://localhost/bar/foo/', 'http://localhost/foo'),
115+
array('../bar/../../foo', 'http://localhost/bar/foo/', 'http://localhost/foo'),
116+
array('../bar/./../../foo', 'http://localhost/bar/foo/', 'http://localhost/foo'),
117+
array('../../', 'http://localhost/', 'http://localhost/'),
118+
array('../../', 'http://localhost', 'http://localhost/'),
104119
);
105120
}
106121
}

src/Symfony/Component/Finder/Iterator/DepthRangeFilterIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DepthRangeFilterIterator extends FilterIterator
3030
public function __construct(\RecursiveIteratorIterator $iterator, $minDepth = 0, $maxDepth = INF)
3131
{
3232
$this->minDepth = $minDepth;
33-
$iterator->setMaxDepth(INF === $maxDepth ? -1 : $maxDepth);
33+
$iterator->setMaxDepth(PHP_INT_MAX === $maxDepth ? -1 : $maxDepth);
3434

3535
parent::__construct($iterator);
3636
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function collect(Request $request, Response $response, \Exception $except
204204
return;
205205
}
206206

207-
$profile = new Profile(uniqid());
207+
$profile = new Profile(sha1(uniqid(mt_rand(), true)));
208208
$profile->setTime(time());
209209
$profile->setUrl($request->getUri());
210210
$profile->setIp($request->getClientIp());

src/Symfony/Component/Routing/RouteCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private static function compilePattern(Route $route, $pattern, $isHost)
147147
}
148148

149149
// find the first optional token
150-
$firstOptional = INF;
150+
$firstOptional = PHP_INT_MAX;
151151
if (!$isHost) {
152152
for ($i = count($tokens) - 1; $i >= 0; $i--) {
153153
$token = $tokens[$i];

0 commit comments

Comments
 (0)
0