From acbafe889d69b427b3f16bb435c3abbc1f46474c Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 4 Jan 2021 20:26:31 +0100 Subject: [PATCH 1/3] do not break when loading schemas from network paths on Windows --- .../Component/DependencyInjection/Loader/XmlFileLoader.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 98ac9345e8..13d02ebb7c 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -614,6 +614,8 @@ class XmlFileLoader extends FileLoader array_shift($parts); $locationstart = 'phar:///'; } + } elseif ('\\' === \DIRECTORY_SEPARATOR && 0 === strpos($location, '\\\\')) { + $locationstart = ''; } $drive = '\\' === \DIRECTORY_SEPARATOR ? array_shift($parts).'/' : ''; $location = $locationstart.$drive.implode('/', array_map('rawurlencode', $parts)); From a33850e838522739e4fc1bc993be530223e917a8 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 5 Jan 2021 09:52:12 +0100 Subject: [PATCH 2/3] make some time dependent tests more resilient --- .../Config/Tests/Resource/DirectoryResourceTest.php | 2 +- .../Mailer/Tests/Transport/Smtp/SmtpTransportTest.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php index fbaed34a21..a956acd87f 100644 --- a/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php @@ -110,7 +110,7 @@ class DirectoryResourceTest extends TestCase { $resource = new DirectoryResource($this->directory); $time = time(); - sleep(1); + usleep(1500000); unlink($this->directory.'/tmp.xml'); $this->assertFalse($resource->isFresh($time), '->isFresh() returns false if an existing file is removed'); } diff --git a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php index 91b1685077..72130dcee4 100644 --- a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php +++ b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php @@ -22,6 +22,9 @@ use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Exception\InvalidArgumentException; use Symfony\Component\Mime\RawMessage; +/** + * @group time-sensitive + */ class SmtpTransportTest extends TestCase { public function testToString() @@ -83,7 +86,7 @@ class SmtpTransportTest extends TestCase $this->assertNotContains("NOOP\r\n", $stream->getCommands()); $stream->clearCommands(); - sleep(1); + usleep(1500000); $transport->send(new RawMessage('Message 3'), $envelope); $this->assertContains("NOOP\r\n", $stream->getCommands()); From 29d2da572e2c24ee14398dbf6479f40fbee3ec57 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 2 Jan 2021 13:40:41 +0100 Subject: [PATCH 3/3] parse cookie values containing the equal sign --- .../Component/HttpFoundation/HeaderUtils.php | 19 +++++- .../HttpFoundation/Tests/CookieTest.php | 6 ++ .../HttpFoundation/Tests/HeaderUtilsTest.php | 62 ++++++++++++------- 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/HeaderUtils.php b/src/Symfony/Component/HttpFoundation/HeaderUtils.php index f4add930eb..fddf2512c4 100644 --- a/src/Symfony/Component/HttpFoundation/HeaderUtils.php +++ b/src/Symfony/Component/HttpFoundation/HeaderUtils.php @@ -193,17 +193,23 @@ class HeaderUtils return $disposition.'; '.self::toString($params, ';'); } - private static function groupParts(array $matches, string $separators): array + private static function groupParts(array $matches, string $separators, bool $first = true): array { $separator = $separators[0]; $partSeparators = substr($separators, 1); $i = 0; $partMatches = []; + $previousMatchWasSeparator = false; foreach ($matches as $match) { - if (isset($match['separator']) && $match['separator'] === $separator) { + if (!$first && $previousMatchWasSeparator && isset($match['separator']) && $match['separator'] === $separator) { + $previousMatchWasSeparator = true; + $partMatches[$i][] = $match; + } elseif (isset($match['separator']) && $match['separator'] === $separator) { + $previousMatchWasSeparator = true; ++$i; } else { + $previousMatchWasSeparator = false; $partMatches[$i][] = $match; } } @@ -211,12 +217,19 @@ class HeaderUtils $parts = []; if ($partSeparators) { foreach ($partMatches as $matches) { - $parts[] = self::groupParts($matches, $partSeparators); + $parts[] = self::groupParts($matches, $partSeparators, false); } } else { foreach ($partMatches as $matches) { $parts[] = self::unquote($matches[0][0]); } + + if (!$first && 2 < \count($parts)) { + $parts = [ + $parts[0], + implode($separator, \array_slice($parts, 1)), + ]; + } } return $parts; diff --git a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php index 55287e082d..e39ca673e0 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php @@ -227,6 +227,12 @@ class CookieTest extends TestCase $cookie = Cookie::fromString('foo', true); $this->assertEquals(Cookie::create('foo', null, 0, '/', null, false, false, false, null), $cookie); + + $cookie = Cookie::fromString('foo_cookie=foo=1&bar=2&baz=3; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/'); + $this->assertEquals(Cookie::create('foo_cookie', 'foo=1&bar=2&baz=3', strtotime('Tue, 22-Sep-2020 06:27:09 GMT'), '/', null, false, false, true, null), $cookie); + + $cookie = Cookie::fromString('foo_cookie=foo==; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/'); + $this->assertEquals(Cookie::create('foo_cookie', 'foo==', strtotime('Tue, 22-Sep-2020 06:27:09 GMT'), '/', null, false, false, true, null), $cookie); } public function testFromStringWithHttpOnly() diff --git a/src/Symfony/Component/HttpFoundation/Tests/HeaderUtilsTest.php b/src/Symfony/Component/HttpFoundation/Tests/HeaderUtilsTest.php index d2b19ca84d..eafcd9311b 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/HeaderUtilsTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/HeaderUtilsTest.php @@ -16,33 +16,47 @@ use Symfony\Component\HttpFoundation\HeaderUtils; class HeaderUtilsTest extends TestCase { - public function testSplit() + /** + * @dataProvider provideHeaderToSplit + */ + public function testSplit(array $expected, string $header, string $separator) { - $this->assertSame(['foo=123', 'bar'], HeaderUtils::split('foo=123,bar', ',')); - $this->assertSame(['foo=123', 'bar'], HeaderUtils::split('foo=123, bar', ',')); - $this->assertSame([['foo=123', 'bar']], HeaderUtils::split('foo=123; bar', ',;')); - $this->assertSame([['foo=123'], ['bar']], HeaderUtils::split('foo=123, bar', ',;')); - $this->assertSame(['foo', '123, bar'], HeaderUtils::split('foo=123, bar', '=')); - $this->assertSame(['foo', '123, bar'], HeaderUtils::split(' foo = 123, bar ', '=')); - $this->assertSame([['foo', '123'], ['bar']], HeaderUtils::split('foo=123, bar', ',=')); - $this->assertSame([[['foo', '123']], [['bar'], ['foo', '456']]], HeaderUtils::split('foo=123, bar; foo=456', ',;=')); - $this->assertSame([[['foo', 'a,b;c=d']]], HeaderUtils::split('foo="a,b;c=d"', ',;=')); + $this->assertSame($expected, HeaderUtils::split($header, $separator)); + } - $this->assertSame(['foo', 'bar'], HeaderUtils::split('foo,,,, bar', ',')); - $this->assertSame(['foo', 'bar'], HeaderUtils::split(',foo, bar,', ',')); - $this->assertSame(['foo', 'bar'], HeaderUtils::split(' , foo, bar, ', ',')); - $this->assertSame(['foo bar'], HeaderUtils::split('foo "bar"', ',')); - $this->assertSame(['foo bar'], HeaderUtils::split('"foo" bar', ',')); - $this->assertSame(['foo bar'], HeaderUtils::split('"foo" "bar"', ',')); + public function provideHeaderToSplit(): array + { + return [ + [['foo=123', 'bar'], 'foo=123,bar', ','], + [['foo=123', 'bar'], 'foo=123, bar', ','], + [[['foo=123', 'bar']], 'foo=123; bar', ',;'], + [[['foo=123'], ['bar']], 'foo=123, bar', ',;'], + [['foo', '123, bar'], 'foo=123, bar', '='], + [['foo', '123, bar'], ' foo = 123, bar ', '='], + [[['foo', '123'], ['bar']], 'foo=123, bar', ',='], + [[[['foo', '123']], [['bar'], ['foo', '456']]], 'foo=123, bar; foo=456', ',;='], + [[[['foo', 'a,b;c=d']]], 'foo="a,b;c=d"', ',;='], - // These are not a valid header values. We test that they parse anyway, - // and that both the valid and invalid parts are returned. - $this->assertSame([], HeaderUtils::split('', ',')); - $this->assertSame([], HeaderUtils::split(',,,', ',')); - $this->assertSame(['foo', 'bar', 'baz'], HeaderUtils::split('foo, "bar", "baz', ',')); - $this->assertSame(['foo', 'bar, baz'], HeaderUtils::split('foo, "bar, baz', ',')); - $this->assertSame(['foo', 'bar, baz\\'], HeaderUtils::split('foo, "bar, baz\\', ',')); - $this->assertSame(['foo', 'bar, baz\\'], HeaderUtils::split('foo, "bar, baz\\\\', ',')); + [['foo', 'bar'], 'foo,,,, bar', ','], + [['foo', 'bar'], ',foo, bar,', ','], + [['foo', 'bar'], ' , foo, bar, ', ','], + [['foo bar'], 'foo "bar"', ','], + [['foo bar'], '"foo" bar', ','], + [['foo bar'], '"foo" "bar"', ','], + + [[['foo_cookie', 'foo=1&bar=2&baz=3'], ['expires', 'Tue, 22-Sep-2020 06:27:09 GMT'], ['path', '/']], 'foo_cookie=foo=1&bar=2&baz=3; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/', ';='], + [[['foo_cookie', 'foo=='], ['expires', 'Tue, 22-Sep-2020 06:27:09 GMT'], ['path', '/']], 'foo_cookie=foo==; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/', ';='], + [[['foo_cookie', 'foo=a=b'], ['expires', 'Tue, 22-Sep-2020 06:27:09 GMT'], ['path', '/']], 'foo_cookie=foo="a=b"; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/', ';='], + + // These are not a valid header values. We test that they parse anyway, + // and that both the valid and invalid parts are returned. + [[], '', ','], + [[], ',,,', ','], + [['foo', 'bar', 'baz'], 'foo, "bar", "baz', ','], + [['foo', 'bar, baz'], 'foo, "bar, baz', ','], + [['foo', 'bar, baz\\'], 'foo, "bar, baz\\', ','], + [['foo', 'bar, baz\\'], 'foo, "bar, baz\\\\', ','], + ]; } public function testCombine()