[BUGFIX] Fix PSR-7 URI generation without scheme 14/58014/4
authorBenni Mack <benni@typo3.org>
Thu, 23 Aug 2018 21:10:45 +0000 (23:10 +0200)
committerHelmut Hummel <typo3@helhum.io>
Fri, 24 Aug 2018 14:33:19 +0000 (16:33 +0200)
When a new Uri('//newpage.com/') is added, TYPO3's PSR-7
implementation lacks the functionality to render that
properly to a string, as - like the specs - say, when there
is an authority, the implementation HAS to prefix the
authority with '//', regardless if there is a scheme or not.

Resolves: #85956
Releases: master
Change-Id: Id888c4425ac2f4a3d9bc9f2a1a3213a872bc55b4
Reviewed-on: https://review.typo3.org/58014
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Tested-by: Helmut Hummel <typo3@helhum.io>
typo3/sysext/core/Classes/Http/Uri.php
typo3/sysext/core/Tests/Unit/Http/UriTest.php

index 2c9c9d6..30254fe 100644 (file)
@@ -577,12 +577,12 @@ class Uri implements UriInterface
         $uri = '';
 
         if (!empty($this->scheme)) {
-            $uri .= $this->scheme . '://';
+            $uri .= $this->scheme . ':';
         }
 
         $authority = $this->getAuthority();
         if (!empty($authority)) {
-            $uri .= $authority;
+            $uri .= '//' . $authority;
         }
 
         $path = $this->getPath();
index 8725676..d90a30c 100644 (file)
@@ -485,6 +485,19 @@ class UriTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
+    public function withEmptySchemeReturnsNewInstanceWithAbsoluteUri()
+    {
+        $uri = new Uri('https://user:pass@local.example.com:3001/foo?bar=baz#quz');
+        $new = $uri->withScheme('');
+        $this->assertNotSame($uri, $new);
+        $this->assertNotSame((string)$uri, (string)$new);
+        $this->assertEquals('', $new->getScheme());
+        $this->assertEquals('//user:pass@local.example.com:3001/foo?bar=baz#quz', (string)$new);
+    }
+
+    /**
+     * @test
+     */
     public function withPathNotSlashPrefixedIsEmittedWithSlashDelimiterWhenUriIsCastToString()
     {
         $uri = new Uri('http://example.com');