8000 Merge branch '2.7' into 2.8 · symfony/symfony@945630a · GitHub
[go: up one dir, main page]

Skip to content

Commit 945630a

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Routing] use constants in tests [Process] tweaked README [Validator] Allow an empty path in a URL with only a fragment or a query [HttpFoundation] Fix some typo in the Request doc fixed CS Added separated handling of root paths
2 parents 6f48ec5 + fa6c58c commit 945630a

File tree

9 files changed

+60
-37
lines changed

9 files changed

+60
-37
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,13 @@ public function makePathRelative($endPath, $startPath)
345345
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
346346
$depth = count($startPathArr) - $index;
347347

348-
// Repeated "../" for each level need to reach the common path
349-
$traverser = str_repeat('../', $depth);
348+
// When we need to traverse from the start, and we are starting from a root path, don't add '../'
349+
if ('/' === $startPath[0] && 0 === $index && 1 === $depth) {
350+
$traverser = '';
351+
} else {
352+
// Repeated "../" for each level need to reach the common path
353+
$traverser = str_repeat('../', $depth);
354+
}
350355

351356
$endPathRemainder = implode('/', array_slice($endPathArr, $index));
352357

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ public function providePathsForMakePathRelative()
790790
array('/a/aab/bb', '/a/aa/', '../aab/bb/'),
791791
array('/a/aab/bb/', '/a/aa', '../aab/bb/'),
792792
array('/a/aab/bb/', '/a/aa/', '../aab/bb/'),
793+
array('/a/aab/bb/', '/', 'a/aab/bb/'),
794+
array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'),
793795
);
794796

795797
if ('\\' === DIRECTORY_SEPARATOR) {

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ public function getQueryString()
11711171
/**
11721172
* Checks whether the request is secure or not.
11731173
*
1174-
* This method can read the client port from the "X-Forwarded-Proto" header
1174+
* This method can read the client protocol from the "X-Forwarded-Proto" header
11751175
* when trusted proxies were set via "setTrustedProxies()".
11761176
*
11771177
* The "X-Forwarded-Proto" header must contain the protocol: "https" or "http".
@@ -1196,7 +1196,7 @@ public function isSecure()
11961196
/**
11971197
* Returns the host name.
11981198
*
1199-
* This method can read the client port from the "X-Forwarded-Host" header
1199+
* This method can read the client host name from the "X-Forwarded-Host" header
12001200
* when trusted proxies were set via "setTrustedProxies()".
12011201
*
12021202
* The "X-Forwarded-Host" header must contain the client host name.

src/Symfony/Component/Process/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ In this example, we run a simple directory listing and get the result back:
77

88
```php
99
use Symfony\Component\Process\Process;
10+
use Symfony\Component\Process\Exception\ProcessFailedException;
1011

1112
$process = new Process('ls -lsa');
1213
$process->setTimeout(3600);
1314
$process->run();
1415
if (!$process->isSuccessful()) {
15-
throw new RuntimeException($process->getErrorOutput());
16+
throw new ProcessFailedException($process);
1617
}
1718

1819
print $process->getOutput();
@@ -21,6 +22,19 @@ print $process->getOutput();
2122
You can think that this is easy to achieve with plain PHP but it's not especially
2223
if you want to take care of the subtle differences between the different platforms.
2324

25+
You can simplify the code by using `mustRun()` instead of `run()`, which will
26+
throw a `ProcessFailedException` automatically in case of a problem:
27+
28+
```php
29+
use Symfony\Component\Process\Process;
30+
31+
$process = new Process('ls -lsa');
32+
$process->setTimeout(3600);
33+
$process->mustRun();
34+
35+
print $process->getOutput();
36+
```
37+
2438
And if you want to be able to get some feedback in real-time, just pass an
2539
anonymous function to the ``run()`` method and you will get the output buffer
2640
as it becomes available:

src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Routing\Tests\Generator\Dumper;
1313

14+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1415
use Symfony\Component\Routing\RouteCollection;
1516
use Symfony\Component\Routing\Route;
1617
use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper;
@@ -64,10 +65,10 @@ public function testDumpWithRoutes()
6465

6566
$projectUrlGenerator = new \ProjectUrlGenerator(new RequestContext('/app.php'));
6667

67-
$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), true);
68-
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), true);
69-
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), false);
70-
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), false);
68+
$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
69+
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_URL);
70+
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
71+
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
7172

7273
$this->assertEquals($absoluteUrlWithParameter, 'http://localhost/app.php/testing/bar');
7374
$this->assertEquals($absoluteUrlWithoutParameter, 'http://localhost/app.php/testing2');

src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,55 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
2222
public function testAbsoluteUrlWithPort80()
2323
{
2424
$routes = $this->getRoutes('test', new Route('/testing'));
25-
$url = $this->getGenerator($routes)->generate('test', array(), true);
25+
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
2626

2727
$this->assertEquals('http://localhost/app.php/testing', $url);
2828
}
2929

3030
public function testAbsoluteSecureUrlWithPort443()
3131
{
3232
$routes = $this->getRoutes('test', new Route('/testing'));
33-
$url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), true);
33+
$url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
3434

3535
$this->assertEquals('https://localhost/app.php/testing', $url);
3636
}
3737

3838
public function testAbsoluteUrlWithNonStandardPort()
3939
{
4040
$routes = $this->getRoutes('test', new Route('/testing'));
41-
$url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), true);
41+
$url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
4242

4343
$this->assertEquals('http://localhost:8080/app.php/testing', $url);
4444
}
4545

4646
public function testAbsoluteSecureUrlWithNonStandardPort()
4747
{
4848
$routes = $this->getRoutes('test', new Route('/testing'));
49-
$url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), true);
49+
$url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
5050

5151
$this->assertEquals('https://localhost:8080/app.php/testing', $url);
5252
}
5353

5454
public function testRelativeUrlWithoutParameters()
5555
{
5656
$routes = $this->getRoutes('test', new Route('/testing'));
57-
$url = $this->getGenerator($routes)->generate('test', array(), false);
57+
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
5858

5959
$this->assertEquals('/app.php/testing', $url);
6060
}
6161

6262
public function testRelativeUrlWithParameter()
6363
{
6464
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
65-
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false);
65+
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
6666

6767
$this->assertEquals('/app.php/testing/bar', $url);
6868
}
6969

7070
public function testRelativeUrlWithNullParameter()
7171
{
7272
$routes = $this->getRoutes('test', new Route('/testing.{format}', array('format' => null)));
73-
$url = $this->getGenerator($routes)->generate('test', array(), false);
73+
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
7474

7575
$this->assertEquals('/app.php/testing', $url);
7676
}
@@ -83,13 +83,13 @@ public function testRelativeUrlWithNullParameterButNotOptional()
8383
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null)));
8484
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
8585
// Generating path "/testing//bar" would be wrong as matching this route would fail.
86-
$this->getGenerator($routes)->generate('test', array(), false);
86+
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
8787
}
8888

8989
public function testRelativeUrlWithOptionalZeroParameter()
9090
{
9191
$routes = $this->getRoutes('test', new Route('/testing/{page}'));
92-
$url = $this->getGenerator($routes)->generate('test', array('page' => 0), false);
92+
$url = $this->getGenerator($routes)->generate('test', array('page' => 0), UrlGeneratorInterface::ABSOLUTE_PATH);
9393

9494
$this->assertEquals('/app.php/testing/0', $url);
9595
}
@@ -104,23 +104,23 @@ public function testNotPassedOptionalParameterInBetween()
104104
public function testRelativeUrlWithExtraParameters()
105105
{
106106
$routes = $this->getRoutes('test', new Route('/testing'));
107-
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false);
107+
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
108108

109109
$this->assertEquals('/app.php/testing?foo=bar', $url);
110110
}
111111

112112
public function testAbsoluteUrlWithExtraParameters()
113113
{
114114
$routes = $this->getRoutes('test', new Route('/testing'));
115-
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
115+
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
116116

117117
$this->assertEquals('http://localhost/app.php/testing?foo=bar', $url);
118118
}
119119

120120
public function testUrlWithNullExtraParameters()
121121
{
122122
$routes = $this->getRoutes('test', new Route('/testing'));
123-
$url = $this->getGenerator($routes)->generate('test', array('foo' => null), true);
123+
$url = $this->getGenerator($routes)->generate('test', array('foo' => null), UrlGeneratorInterface::ABSOLUTE_URL);
124124

125125
$this->assertEquals('http://localhost/app.php/testing', $url);
126126
}
@@ -167,7 +167,7 @@ public function testGlobalParameterHasHigherPriorityThanDefault()
167167
public function testGenerateWithoutRoutes()
168168
{
169169
$routes = $this->getRoutes('foo', new Route('/testing/{foo}'));
170-
$this->getGenerator($routes)->generate('test', array(), true);
170+
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
171171
}
172172

173173
/**
@@ -176,7 +176,7 @@ public function testGenerateWithoutRoutes()
176176
public function testGenerateForRouteWithoutMandatoryParameter()
177177
{
178178
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
179-
$this->getGenerator($routes)->generate('test', array(), true);
179+
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
180180
}
181181

182182
/**
@@ -185,7 +185,7 @@ public function testGenerateForRouteWithoutMandatoryParameter()
185185
public function testGenerateForRouteWithInvalidOptionalParameter()
186186
{
187187
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
188-
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
188+
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
189189
}
190190

191191
/**
@@ -194,15 +194,15 @@ public function testGenerateForRouteWithInvalidOptionalParameter()
194194
public function testGenerateForRouteWithInvalidParameter()
195195
{
196196
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '1|2')));
197-
$this->getGenerator($routes)->generate('test', array('foo' => '0'), true);
197+
$this->getGenerator($routes)->generate('test', array('foo' => '0'), UrlGeneratorInterface::ABSOLUTE_URL);
198198
}
199199

200200
public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
201201
{
202202
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
203203
$generator = $this->getGenerator($routes);
204204
$generator->setStrictRequirements(false);
205-
$this->assertNull($generator->generate('test', array('foo' => 'bar'), true));
205+
$this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL));
206206
}
207207

208208
public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()
@@ -213,7 +213,7 @@ public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLog
213213
->method('error');
214214
$generator = $this->getGenerator($routes, array(), $logger);
215215
$generator->setStrictRequirements(false);
216-
$this->assertNull($generator->generate('test', array('foo' => 'bar'), true));
216+
$this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL));
217217
}
218218

219219
public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck()
@@ -230,7 +230,7 @@ public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsC
230230
public function testGenerateForRouteWithInvalidMandatoryParameter()
231231
{
232232
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+')));
233-
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
233+
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
234234
}
235235

236236
/**
@@ -411,7 +411,7 @@ public function testWithHostSameAsContextAndAbsolute()
411411
{
412412
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));
413413

414-
$this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr'), true));
414+
$this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL));
415415
}
416416

417417
/**
@@ -420,7 +420,7 @@ public function testWithHostSameAsContextAndAbsolute()
420420
public function testUrlWithInvalidParameterInHost()
421421
{
422422
$routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com'));
423-
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false);
423+
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
424424
}
425425

426426
/**
@@ -429,7 +429,7 @@ public function testUrlWithInvalidParameterInHost()
429429
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
430430
{
431431
$routes = $this->getRoutes('test', new Route('/', array('foo' => 'bar'), array('foo' => 'bar'), array(), '{foo}.example.com'));
432-
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false);
432+
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
433433
}
434434

435435
/**
@@ -438,15 +438,15 @@ public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
438438
public function testUrlWithInvalidParameterEqualsDefaultValueInHost()
439439
{
440440
$routes = $this->getRoutes('test', new Route('/', array('foo' => 'baz'), array('foo' => 'bar'), array(), '{foo}.example.com'));
441-
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), false);
441+
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
442442
}
443443

444444
public function testUrlWithInvalidParameterInHostInNonStrictMode()
445445
{
446446
$routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com'));
447447
$generator = $this->getGenerator($routes);
448448
$generator->setStrictRequirements(false);
449-
$this->assertNull($generator->generate('test', array('foo' => 'baz'), false));
449+
$this->assertNull($generator->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH));
450450
}
451451

452452
public function testHostIsCaseInsensitive()

src/Symfony/Component/Security/Http/Tests/HttpUtilsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
1616
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
1717
use Symfony\Component\Security\Core\Security;
18+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1819
use Symfony\Component\Security\Http\HttpUtils;
1920

2021
class HttpUtilsTest extends \PHPUnit_Framework_TestCase
@@ -43,7 +44,7 @@ public function testCreateRedirectResponseWithRouteName()
4344
$urlGenerator
4445
->expects($this->any())
4546
->method('generate')
46-
->with('foobar', array(), true)
47+
->with('foobar', array(), UrlGeneratorInterface::ABSOLUTE_URL)
4748
->will($this->returnValue('http://localhost/foo/bar'))
4849
;
4950
$urlGenerator

src/Symfony/Component/Validator/Constraints/UrlValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class UrlValidator extends ConstraintValidator
3434
\] # a IPv6 address
3535
)
3636
(:[0-9]+)? # a port (optional)
37-
(/?|/\S+) # a /, nothing or a / with something
37+
(/?|/\S+|\?|\#) # a /, nothing, a / with something, a query or a fragment
3838
$~ixu';
3939

4040
/**

src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public function getValidUrls()
117117
array('http://☎.com/'),
118118
array('http://username:password@symfony.com'),
119119
array('http://user-name@symfony.com'),
120+
array('http://symfony.com?'),
121+
array('http://symfony.com#'),
120122
);
121123
}
122124

@@ -147,8 +149,6 @@ public function getInvalidUrls()
147149
array('http://goog_le.com'),
148150
array('http://google.com::aa'),
149151
array('http://google.com:aa'),
150-
array('http://symfony.com?'),
151-
array('http://symfony.com#'),
152152
array('ftp://google.fr'),
153153
array('faked://google.fr'),
154154
array('http://127.0.0.1:aa/'),

0 commit comments

Comments
 (0)
0