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 adb137d

Browse filesBrowse files
Merge branch '4.1'
* 4.1: [Routing] Disallow object usage inside Route [HttpFoundation] missing namespace for RedisProxy [Routing] fix too much greediness in host-matching regex [HttpFoundation] fix registration of session proxies failing test to reproduce session problem [HttpFoundation] fix session tracking counter
2 parents 0c57f00 + 223cf06 commit adb137d
Copy full SHA for adb137d

File tree

Expand file treeCollapse file tree

14 files changed

+202
-103
lines changed
Filter options
Expand file treeCollapse file tree

14 files changed

+202
-103
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SessionController.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SessionController.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public function welcomeAction(Request $request, $name = null)
4343
return new Response(sprintf('Welcome back %s, nice to meet you.', $name));
4444
}
4545

46+
public function cacheableAction()
47+
{
48+
$response = new Response('all good');
49+
$response->setSharedMaxAge(100);
50+
51+
return $response;
52+
}
53+
4654
public function logoutAction(Request $request)
4755
{
4856
$request->getSession()->invalidate();

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ session_welcome:
22
path: /session
33
defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::welcomeAction }
44

5+
session_cacheable:
6+
path: /cacheable
7+
defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::cacheableAction }
8+
59
session_welcome_name:
610
path: /session/{name}
711
defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::welcomeAction }

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ public function testTwoClients($config, $insulate)
126126
$this->assertContains('Welcome back client2, nice to meet you.', $crawler2->text());
127127
}
128128

129+
/**
130+
* @dataProvider getConfigs
131+
*/
132+
public function testCorrectCacheControlHeadersForCacheableAction($config, $insulate)
133+
{
134+
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
135+
if ($insulate) {
136+
$client->insulate();
137+
}
138+
139+
$client->request('GET', '/cacheable');
140+
141+
$response = $client->getResponse();
142+
$this->assertSame('public, s-maxage=100', $response->headers->get('cache-control'));
143+
}
144+
129145
public function getConfigs()
130146
{
131147
return array(

‎src/Symfony/Component/HttpFoundation/Session/Session.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Session.php
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public function __construct(SessionStorageInterface $storage = null, AttributeBa
5454
*/
5555
public function start()
5656
{
57-
++$this->usageIndex;
58-
5957
return $this->storage->start();
6058
}
6159

@@ -160,7 +158,9 @@ public function getUsageIndex()
160158
*/
161159
public function isEmpty()
162160
{
163-
++$this->usageIndex;
161+
if ($this->isStarted()) {
162+
++$this->usageIndex;
163+
}
164164
foreach ($this->data as &$data) {
165165
if (!empty($data)) {
166166
return false;
@@ -185,8 +185,6 @@ public function invalidate($lifetime = null)
185185
*/
186186
public function migrate($destroy = false, $lifetime = null)
187187
{
188-
++$this->usageIndex;
189-
190188
return $this->storage->regenerate($destroy, $lifetime);
191189
}
192190

@@ -195,8 +193,6 @@ public function migrate($destroy = false, $lifetime = null)
195193
*/
196194
public function save()
197195
{
198-
++$this->usageIndex;
199-
200196
$this->storage->save();
201197
}
202198

‎src/Symfony/Component/HttpFoundation/Session/SessionBagProxy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/SessionBagProxy.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function getBag()
4444
*/
4545
public function isEmpty()
4646
{
47+
if (!isset($this->data[$this->bag->getStorageKey()])) {
48+
return true;
49+
}
4750
++$this->usageIndex;
4851

4952
return empty($this->data[$this->bag->getStorageKey()]);
@@ -81,8 +84,6 @@ public function getStorageKey()
8184
*/
8285
public function clear()
8386
{
84-
++$this->usageIndex;
85-
8687
return $this->bag->clear();
8788
}
8889
}

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
1313

1414
use Predis\Response\ErrorInterface;
15+
use Symfony\Component\Cache\Traits\RedisProxy;
1516

1617
/**
1718
* Redis based session storage handler based on the Redis class

‎src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,6 @@ public function setSaveHandler($saveHandler = null)
407407
}
408408

409409
if ($this->saveHandler instanceof SessionHandlerProxy) {
410-
session_set_save_handler($this->saveHandler->getHandler(), false);
411-
} elseif ($this->saveHandler instanceof \SessionHandlerInterface) {
412410
session_set_save_handler($this->saveHandler, false);
413411
}
414412
}

‎src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php
+17-1Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @author Drak <drak@zikula.org>
1616
*/
17-
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface
17+
class SessionHandlerProxy extends AbstractProxy implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
1818
{
1919
protected $handler;
2020

@@ -82,4 +82,20 @@ public function gc($maxlifetime)
8282
{
8383
return (bool) $this->handler->gc($maxlifetime);
8484
}
85+
86+
/**
87+
* {@inheritdoc}
88+
*/
89+
public function validateId($sessionId)
90+
{
91+
return !$this->handler instanceof \SessionUpdateTimestampHandlerInterface || $this->handler->validateId($sessionId);
92+
}
93+
94+
/**
95+
* {@inheritdoc}
96+
*/
97+
public function updateTimestamp($sessionId, $data)
98+
{
99+
return $this->handler instanceof \SessionUpdateTimestampHandlerInterface ? $this->handler->updateTimestamp($sessionId, $data) : $this->write($sessionId, $data);
100+
}
85101
}

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,37 @@ public function testGc()
121121

122122
$this->proxy->gc(86400);
123123
}
124+
125+
/**
126+
* @requires PHPUnit 5.1
127+
*/
128+
public function testValidateId()
129+
{
130+
$mock = $this->getMockBuilder(array('SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'))->getMock();
131+
$mock->expects($this->once())
132+
->method('validateId');
133+
134+
$proxy = new SessionHandlerProxy($mock);
135+
$proxy->validateId('id');
136+
137+
$this->assertTrue($this->proxy->validateId('id'));
138+
}
139+
140+
/**
141+
* @requires PHPUnit 5.1
142+
*/
143+
public function testUpdateTimestamp()
144+
{
145+
$mock = $this->getMockBuilder(array('SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'))->getMock();
146+
$mock->expects($this->once())
147+
->method('updateTimestamp');
148+
149+
$proxy = new SessionHandlerProxy($mock);
150+
$proxy->updateTimestamp('id', 'data');
151+
152+
$this->mock->expects($this->once())
153+
->method('write');
154+
155+
$this->proxy->updateTimestamp('id', 'data');
156+
}
124157
}

‎src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ private function compileDynamicRoutes(RouteCollection $collection, bool $matchHo
379379
$hostRegex = '(?i:'.preg_replace_callback('#\?P<([^>]++)>#', $state->getVars, $rx[1]).')\.';
380380
$state->hostVars = $state->vars;
381381
} else {
382-
$hostRegex = '(?:(?:[^.]*+\.)++)';
382+
$hostRegex = '(?:(?:[^./]*+\.)++)';
383383
$state->hostVars = array();
384384
}
385385
$state->mark += strlen($rx = ($prev ? ')' : '')."|{$hostRegex}(?");
@@ -746,6 +746,10 @@ public static function export($value): string
746746
return 'null';
747747
}
748748
if (!\is_array($value)) {
749+
if (\is_object($value)) {
750+
throw new \InvalidArgumentException('Symfony\Component\Routing\Route cannot contain objects.');
751+
}
752+
749753
return str_replace("\n", '\'."\n".\'', var_export($value, true));
750754
}
751755
if (!$value) {

‎src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php
+45-45Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -82,47 +82,47 @@ public function match($rawPathinfo)
8282
$matchedPathinfo = $host.'.'.$pathinfo;
8383
$regexList = array(
8484
0 => '{^(?'
85-
.'|(?:(?:[^.]*+\\.)++)(?'
86-
.'|/foo/(baz|symfony)(*:46)'
85+
.'|(?:(?:[^./]*+\\.)++)(?'
86+
.'|/foo/(baz|symfony)(*:47)'
8787
.'|/bar(?'
88-
.'|/([^/]++)(*:69)'
89-
.'|head/([^/]++)(*:89)'
88+
.'|/([^/]++)(*:70)'
89+
.'|head/([^/]++)(*:90)'
9090
.')'
9191
.'|/test/([^/]++)/(?'
92-
.'|(*:115)'
92+
.'|(*:116)'
9393
.')'
94-
.'|/([\']+)(*:131)'
94+
.'|/([\']+)(*:132)'
9595
.'|/a/(?'
9696
.'|b\'b/([^/]++)(?'
97-
.'|(*:160)'
98-
.'|(*:168)'
97+
.'|(*:161)'
98+
.'|(*:169)'
9999
.')'
100-
.'|(.*)(*:181)'
100+
.'|(.*)(*:182)'
101101
.'|b\'b/([^/]++)(?'
102-
.'|(*:204)'
103-
.'|(*:212)'
102+
.'|(*:205)'
103+
.'|(*:213)'
104104
.')'
105105
.')'
106-
.'|/multi/hello(?:/([^/]++))?(*:248)'
106+
.'|/multi/hello(?:/([^/]++))?(*:249)'
107107
.'|/([^/]++)/b/([^/]++)(?'
108-
.'|(*:279)'
109-
.'|(*:287)'
108+
.'|(*:280)'
109+
.'|(*:288)'
110110
.')'
111-
.'|/aba/([^/]++)(*:309)'
111+
.'|/aba/([^/]++)(*:310)'
112112
.')|(?i:([^\\.]++)\\.example\\.com)\\.(?'
113113
.'|/route1(?'
114-
.'|3/([^/]++)(*:371)'
115-
.'|4/([^/]++)(*:389)'
114+
.'|3/([^/]++)(*:372)'
115+
.'|4/([^/]++)(*:390)'
116116
.')'
117117
.')|(?i:c\\.example\\.com)\\.(?'
118-
.'|/route15/([^/]++)(*:441)'
119-
.')|(?:(?:[^.]*+\\.)++)(?'
120-
.'|/route16/([^/]++)(*:488)'
118+
.'|/route15/([^/]++)(*:442)'
119+
.')|(?:(?:[^./]*+\\.)++)(?'
120+
.'|/route16/([^/]++)(*:490)'
121121
.'|/a/(?'
122-
.'|a\\.\\.\\.(*:509)'
122+
.'|a\\.\\.\\.(*:511)'
123123
.'|b/(?'
124-
.'|([^/]++)(*:530)'
125-
.'|c/([^/]++)(*:548)'
124+
.'|([^/]++)(*:532)'
125+
.'|c/([^/]++)(*:550)'
126126
.')'
127127
.')'
128128
.')'
@@ -132,7 +132,7 @@ public function match($rawPathinfo)
132132
foreach ($regexList as $offset => $regex) {
133133
while (preg_match($regex, $matchedPathinfo, $matches)) {
134134
switch ($m = (int) $matches['MARK']) {
135-
case 115:
135+
case 116:
136136
$matches = array('foo' => $matches[1] ?? null);
137137

138138
// baz4
@@ -159,7 +159,7 @@ public function match($rawPathinfo)
159159
not_bazbaz6:
160160

161161
break;
162-
case 160:
162+
case 161:
163163
$matches = array('foo' => $matches[1] ?? null);
164164

165165
// foo1
@@ -173,14 +173,14 @@ public function match($rawPathinfo)
173173
not_foo1:
174174

175175
break;
176-
case 204:
176+
case 205:
177177
$matches = array('foo1' => $matches[1] ?? null);
178178

179179
// foo2
180180
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
181181

182182
break;
183-
case 279:
183+
case 280:
184184
$matches = array('_locale' => $matches[1] ?? null, 'foo' => $matches[2] ?? null);
185185

186186
// foo3
@@ -189,23 +189,23 @@ public function match($rawPathinfo)
189189
break;
190190
default:
191191
$routes = array(
192-
46 => array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null),
193-
69 => array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null),
194-
89 => array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null),
195-
131 => array(array('_route' => 'quoter'), array('quoter'), null, null),
196-
168 => array(array('_route' => 'bar1'), array('bar'), null, null),
197-
181 => array(array('_route' => 'overridden'), array('var'), null, null),
198-
212 => array(array('_route' => 'bar2'), array('bar1'), null, null),
199-
248 => array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null),
200-
287 => array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null),
201-
309 => array(array('_route' => 'foo4'), array('foo'), null, null),
202-
371 => array(array('_route' => 'route13'), array('var1', 'name'), null, null),
203-
389 => array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null),
204-
441 => array(array('_route' => 'route15'), array('name'), null, null),
205-
488 => array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null),
206-
509 => array(array('_route' => 'a'), array(), null, null),
207-
530 => array(array('_route' => 'b'), array('var'), null, null),
208-
548 => array(array('_route' => 'c'), array('var'), null, null),
192+
47 => array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null),
193+
70 => array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null),
194+
90 => array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null),
195+
132 => array(array('_route' => 'quoter'), array('quoter'), null, null),
196+
169 => array(array('_route' => 'bar1'), array('bar'), null, null),
197+
182 => array(array('_route' => 'overridden'), array('var'), null, null),
198+
213 => array(array('_route' => 'bar2'), array('bar1'), null, null),
199+
249 => array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null),
200+
288 => array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null),
201+
310 => array(array('_route' => 'foo4'), array('foo'), null, null),
202+
372 => array(array('_route' => 'route13'), array('var1', 'name'), null, null),
203+
390 => array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null),
204+
442 => array(array('_route' => 'route15'), array('name'), null, null),
205+
490 => array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null),
206+
511 => array(array('_route' => 'a'), array(), null, null),
207+
532 => array(array('_route' => 'b'), array('var'), null, null),
208+
550 => array(array('_route' => 'c'), array('var'), null, null),
209209
);
210210

211211
list($ret, $vars, $requiredMethods, $requiredSchemes) = $routes[$m];
@@ -231,7 +231,7 @@ public function match($rawPathinfo)
231231
return $ret;
232232
}
233233

234-
if (548 === $m) {
234+
if (550 === $m) {
235235
break;
236236
}
237237
$regex = substr_replace($regex, 'F', $m - $offset, 1 + strlen($m));

0 commit comments

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