Merge branch '4.4' into 5.1

* 4.4:
  [HttpFoundation] Make test pass without Xdebug.
  [Mime] Leverage PHP 8's detection of CSV files.
  [HttpFoundation] Make sure we reuse the current PHP binary for the webserver process in functional tests.
  [FrameworkBundle] TextDescriptor::formatControllerLink checked method…
  Fix CS
  [HttpClient] throw clearer error when no scheme is provided
  Fix github pr template and include 5.2 for bugfixes
  [HttpFoundation] Ignore stack trace printed by Xdebug 3.
  fix lexing backslashes in single quoted strings
This commit is contained in:
Alexander M. Turek 2020-12-05 11:32:07 +01:00
commit 2cf0686f72
12 changed files with 53 additions and 7 deletions

View File

@ -1,6 +1,6 @@
| Q | A
| ------------- | ---
| Branch? | 5.x for features / 4.4 or 5.1 for bug fixes <!-- see below -->
| Branch? | 5.x for features / 4.4, 5.1 or 5.2 for bug fixes <!-- see below -->
| Bug fix? | yes/no
| New feature? | yes/no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | yes/no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->

View File

@ -535,7 +535,9 @@ class TextDescriptor extends Descriptor
}
try {
if (\is_array($controller)) {
if (null === $controller) {
return $anchorText;
} elseif (\is_array($controller)) {
$r = new \ReflectionMethod($controller[0], $controller[1]);
} elseif ($controller instanceof \Closure) {
$r = new \ReflectionFunction($controller);

View File

@ -391,6 +391,10 @@ trait HttpClientTrait
throw new InvalidArgumentException(sprintf('Invalid "base_uri" option: host or scheme is missing in "%s".', implode('', $base)));
}
if (null === $url['scheme'] && (null === $base || null === $base['scheme'])) {
throw new InvalidArgumentException(sprintf('Invalid URL: scheme is missing in "%s". Did you forget to add "http(s)://"?', implode('', $base ?? $url)));
}
if (null === $base && '' === $url['scheme'].$url['authority']) {
throw new InvalidArgumentException(sprintf('Invalid URL: no "base_uri" option was provided and host or scheme is missing in "%s".', implode('', $url)));
}

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpClient\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
use Symfony\Component\HttpClient\HttpClientTrait;
use Symfony\Contracts\HttpClient\HttpClientInterface;
@ -120,6 +121,20 @@ class HttpClientTraitTest extends TestCase
];
}
public function testResolveUrlWithoutScheme()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid URL: scheme is missing in "//localhost:8080". Did you forget to add "http(s)://"?');
self::resolveUrl(self::parseUrl('localhost:8080'), null);
}
public function testResolveBaseUrlWitoutScheme()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid URL: scheme is missing in "//localhost:8081". Did you forget to add "http(s)://"?');
self::resolveUrl(self::parseUrl('/foo'), self::parseUrl('localhost:8081'));
}
/**
* @dataProvider provideParseUrl
*/

View File

@ -1,6 +1,6 @@
Warning: Expiry date cannot have a year greater than 9999 in %scookie_max_age.php on line 10
%A
Array
(
[0] => Content-Type: text/plain; charset=utf-8

View File

@ -23,7 +23,7 @@ class ResponseFunctionalTest extends TestCase
1 => ['file', '/dev/null', 'w'],
2 => ['file', '/dev/null', 'w'],
];
if (!self::$server = @proc_open('exec php -S localhost:8054', $spec, $pipes, __DIR__.'/Fixtures/response-functional')) {
if (!self::$server = @proc_open('exec '.\PHP_BINARY.' -S localhost:8054', $spec, $pipes, __DIR__.'/Fixtures/response-functional')) {
self::markTestSkipped('PHP server unable to start.');
}
sleep(1);

View File

@ -23,7 +23,7 @@ class AbstractSessionHandlerTest extends TestCase
1 => ['file', '/dev/null', 'w'],
2 => ['file', '/dev/null', 'w'],
];
if (!self::$server = @proc_open('exec php -S localhost:8053', $spec, $pipes, __DIR__.'/Fixtures')) {
if (!self::$server = @proc_open('exec '.\PHP_BINARY.' -S localhost:8053', $spec, $pipes, __DIR__.'/Fixtures')) {
self::markTestSkipped('PHP server unable to start.');
}
sleep(1);

View File

@ -166,6 +166,7 @@ final class MimeTypes implements MimeTypesInterface
'application/cdmi-queue' => ['cdmiq'],
'application/cdr' => ['cdr'],
'application/coreldraw' => ['cdr'],
'application/csv' => ['csv'],
'application/cu-seeme' => ['cu'],
'application/davmount+xml' => ['davmount'],
'application/dbase' => ['dbf'],
@ -1818,7 +1819,7 @@ final class MimeTypes implements MimeTypesInterface
'csp' => ['application/vnd.commonspace'],
'css' => ['text/css'],
'cst' => ['application/x-director'],
'csv' => ['text/csv', 'text/x-comma-separated-values', 'text/x-csv'],
'csv' => ['text/csv', 'text/x-comma-separated-values', 'text/x-csv', 'application/csv'],
'csvs' => ['text/csv-schema'],
'cu' => ['application/cu-seeme'],
'cue' => ['application/x-cue'],

View File

@ -0,0 +1,3 @@
a,b,c
d,e,f
g,h,i
1 a b c
2 d e f
3 g h i

View File

@ -73,4 +73,18 @@ class MimeTypesTest extends AbstractMimeTypeGuesserTest
$this->assertContains('text/baz', $mt->getMimeTypes('foo'));
$this->assertSame(['foo', 'moof'], $mt->getExtensions('text/baz'));
}
/**
* PHP 8 detects .csv files as "application/csv" while PHP 7 returns "text/plain".
*
* @requires PHP 8
*/
public function testCsvExtension()
{
$mt = new MimeTypes();
$mime = $mt->guessMimeType(__DIR__.'/Fixtures/mimetypes/abc.csv');
$this->assertSame('application/csv', $mime);
$this->assertSame(['csv'], $mt->getExtensions($mime));
}
}

View File

@ -1178,7 +1178,9 @@ class Parser
for (; \strlen($this->currentLine) > $cursor; ++$cursor) {
switch ($this->currentLine[$cursor]) {
case '\\':
if (isset($this->currentLine[++$cursor])) {
if ("'" === $quotation) {
$value .= '\\';
} elseif (isset($this->currentLine[++$cursor])) {
$value .= '\\'.$this->currentLine[$cursor];
}

View File

@ -1617,6 +1617,11 @@ YAML
];
}
public function testBackslashInSingleQuotedString()
{
$this->assertSame(['foo' => 'bar\\'], $this->parser->parse("foo: 'bar\'"));
}
public function testParseMultiLineString()
{
$this->assertEquals("foo bar\nbaz", $this->parser->parse("foo\nbar\n\nbaz"));